Wordpress article and dynamic data/graphs, images to PDF - php

I'm using Wordpress to manage a newsletter with IssueM, also I need to be able to export the content of a group of articles to PDF (Keep in mind that I'm not a php hardcore developer).I'm using Advanced Custom Fields to generate some data and then creating graphs using NVD3 with javascript.
At this time, all the plugins I found to create PDF's did not work, they only "print" the title of the post(article in IssueM) and nothing else.
I need to be able to export the content, rendered graphs and tables with images, to PDF as they appear in the browser (styled via CSS in my page).
I found there is FPDF, and mPDF, also DOMPDF but they don't specify if they can render the javascript output (which are my NVD3 rendered graphs) to PDF.
Is there any tool that can acomplish this? or,
Do I have to do this by hand? If that's the case, can you tell me an approach?

Have you had a look at:
https://wordpress.org/plugins/printfriendly/
You should be able to add/remove/customize elements that print out:
http://support.printfriendly.com/publisher/developer-questions/include-exclude-content/
It should render javascript because it is using javascript (make sure you enable javascript use in the plugin):
http://support.printfriendly.com/publisher/wordpress/javascript-option/
Hope that helps!

Related

How to create a single download link for 2 pdf files in php

I'm very new to PHP and wanted to know how to create a single download link for 2 pdf files using php. Do I need to write an individual download.php file to execute or can I simply add it to my index page using an tag in html? I need it to work across all browsers.
I have 2 documents that are in their own folder named "forms" and not sure how to create a simple text link that will let a user download both documents in a single click.
I agree with the other answers, this is not the best practice, you should use one button/link for each file, it's even easier to understand what's been displayed for the user. You should probably use two icons or links.
Look up for w3schools, they have good tutorials of how to use icons, links, html, css and javascript.
There are some links:
https://www.w3schools.com/html/html_links.asp
https://www.w3schools.com/w3css/w3css_icons.asp
https://www.w3schools.com/icons/fontawesome5_icons_computers.asp

How to implement an editable textarea component on a PDF generated by TCPDF library?

I am trying to create an editable HTML textarea component using TCPDF API library. I want to display a scrollable text box on the screen.
Can this be done?
Current TCPDF examples include these: https://tcpdf.org/examples/
I know PDFs can have editable components, but I am not sure how to create them with TCPDF, if it is at all possible.
TD;DR: how can I generate a page with a scrollable textarea using PHP + TCPDF?
Linked Answer using another library (mPDF):
Note that while How to create editable Pdf form in php may work, it does not make use of TCPDF library. My existing codebase relies heavily on TCPDF, I would like to explore the possibility of using TCPDF before I consider adding another library ...
i.e. I rather have an answer of "Not possible" than to use another library at this time.
It looks like the issue is two-fold.
First, you can use a typical form example, like here: https://tcpdf.org/examples/example_054/
However, you cannot see editable fields in a browser, at least you cannot in Mozilla Firefox 56.0.2 as the time of this writing. (https://support.mozilla.org/en-US/questions/1006115)
What you need to do is open the generated PDF in a different viewer that supports editable form fields, such as Adobe PDF reader/other.
Then you can fill out the textarea and if text size exceeds the area of the form element, it will have scroll bars added to the textarea.

What is the easiest method to allow someone to download a PDF copy of a HTML page?

I have a HTML page that contains a table with a list of a customers orders (pulled from a database via PHP).
I want to have a button on the page that will allow the users to download a PDF copy excluding the navigation bar etc.
The examples that I've seen and tested online initially load the page in PDF format but I don't want this. I want it to load as it currently is but also have a button that when pressed downloads a PDF copy (i.e. not display it in the browser).
wkhtmltopdf will do the trick:
http://wkhtmltopdf.org/
It should allow you a lot of customization options.
But if you want to generate it dynamically then you have to use some library for pdf . There are many library like tcpdf, dompdf etc.
Dom pdf example
From experience I would recommend Phantom JS - see an example
I found Phantom JS offers better HTML/CSS support when compared to wkhtmltopdf.
Bear in mind, you will struggle to get support for things like CSS3 columns in Phantom and Wkhtmltopdf.
Workflow:
Land on initial page (later to be converted to PDF).
Display button - 'download as PDF'
Listen for the click event on this button and call a custom callback
function once the event is fired.
The callback function executes an Ajax call sending the full page
HTML as part of the server request.
On server side, fire up Phantom JS or Wkhtmltopdf to generate PDF. Save
PDF on server.
Generate URL for saved PDF and display/load client side.
PS; I'm not sure if Phantom JS will generate a PDF from a string or whether it expects a valid url. I know Wkhtmltopdf can generate a PDF from a string.
Hope this helps
Since you ask for the easiest way.. just print the HTML client side. This button invokes printing the web page client side:
<input type="button"
onClick="window.print()"
value="Print This Page"/>
Then the user would have to select a PDF printer driver. Chrome has this built in.
Here you can read how to exclude parts of the HTML (such as the print button itself) from being printed:
How do I hide an element when printing a web page?

PHP page to PDF with object oriented websites

I'm trying to get my shopping cart items to a pdf to create an invoice
I have url which shows the invoice in html/css like this:
index.php?module=checkout&view=topdf
If I want to get the content of that page to use in mPDF or other pdf libraries using file_get_contents or cURL it doesn't give any content because the url is not an actual file on the server
How can I fix this? I work with templates and don't know how can I export the current php page to a html page
I used TCPDF for something similar. Getting the formatting right is a bit of a pain but once you've got that it's a really good bit of work.
http://www.tcpdf.org/examples.php

how to display PDF in a php site?

I am new to codeigniter, and not so new to PHP. I am developing a site that has a login for 2 users and once they login, it'll show an optin to view an invoice. I am not making the invoice since I have a stack of invoices already. I want to do it so that once they click on view invoice they can see a PDF. I have searched but I ask you for some idea in the visualization of PDF in codeigniter?
I'm guessing that you want to generate pdfs. There is a library called dompdf that lets you do it quite easily and there is documentation on using that with Codeigniter.
If you're wondering how to link between a pdf and a customer, I'd suggest adding a field in the database to match each customer or perhaps a whole table depending on your use case.
Not sure if I understand your question but here goes...
If you just want to marshal an existing PDF file via PHP, its basically a case of
Send the appropriate "Content-Type" response headers for a PDF file, eg application/pdf
Deliver the file contents using something like readfile()
From my understanding, you have a directory of PDFs that need to be displayed to the user.
This is usually handled by the PDF software. Adobe Reader can render the PDF in the browser and so can newer releases of the Chromium which have PDF viewing built in.
Make sure you send the correct response headers as Phil Brown points out and you're all set.

Categories