I'm using a PHP Output Buffer to create an HTML file of a dynamic 'Data Review' page, I then save this output as an HTML file to the server and would like to create a PDF file of this HTML file (stored on the server) but every solution I've looked at requires you to put in HTML code into a variable, but I have the .HTML file that I want to convert to PDF automatically but can't seem to find a solution.
The overall idea here is to supply the user a 'copy' of the data review via email, so I assumed a PDF would be best, but if there are any other suggestions, I would happily consider something else.
Any help would be greatly appreciated.
Thank you!
I've looked heavily into generating PDFs in PHP and so here is what I've found over a few years...
FPDF
This option is really good if you want to generate a PDF file using the PDF method (I will coin it this because you literally generate the PDF piece by piece).
Features include:
- Choice of measure unit, page format and margins
- Page header and footer management
- Automatic page break
- Automatic line break and text justification
- Image support (JPEG, PNG and GIF)
- Colors
- Links
- TrueType, Type1 and encoding support
- Page compression
Notes
Fast
Free
Difficult
- PDF generation from UTF-8 encoded HTML
- It is based on FPDF and HTML2FPDF with a number of enhancements
Mediocre
Free
Easy
- Powerful Layout
- Headers and footers
- Page numbers, duplex printing
- Tables, lists, columns, floats
- Footnotes, cross-references
- Web Standards
- HTML, XHTML, XML, SVG
- Cascading Style Sheets (CSS)
- JavaScript/ECMAScript
- JPEG, PNG, GIF, TIFF
- PDF Output
- Bookmarks, links, metadata
- Encryption and Document Security
- Font embedding and subsetting
- PDF attachments
- Easy Integration
- PHP and Ruby on Rails
- Java class for servlets
- .NET for C# and ASP
- ActiveX/COM for VB6
- Fonts & Unicode
- OpenType fonts, TrueType and CFF
- Kerning, Ligatures, Small Caps
- Chinese, Japanese, Korean, Arabic, Hebrew, Hindi and others
- Friendly Support
- Prompt email support
- Web forum, user guide
- Regular upgrades
Fast
$$$
- 1 license - $3,800
- 2 license - $3,420
- 3 license - $3,040
- 4 license - $2,850
- 5+ license - $2,800
Easy
DocRaptor
This option is really good if you want a high quality API. This is a cloud-hosted option for creating PDF and XLS files. Uses PrinceXML in the backend.
Features include:
- You just send HTML, JS, and CSS
- Uptime guaranteed
- Unlimited document size
- Expert support, including document debugging
Fast
$
- $$$
- Basic - 125 docs/mo - $15/mo
- Professional - 325 docs/mo - $29/mo
- Premium - 1,250 docs/mo - $75/mo
- Max - 5,000 docs/mo - $149/mo
- Bronze - 15,000 docs/mo - $399/mo
- Silver - 40,000 docs/mo - $1,000/mo
- Gold - 100,000 docs/mo - $2,250/mo
- Enterprise - ∞ docs/mo - unlisted (contact them)
Very easy
- [Uses] the Qt WebKit rendering engine
- Create your HTML document that you want to turn into a PDF (or image). Run your HTML document through the tool.
Fast
Free
Easy
$_SESSION
variables as this is ran through the command line and uses a separate browser. You need to pass all your variables through $_GET
variables.system()
: Source 1, Source 2
We deal with many vendors. Some vendors send us PDFs for their invoices or other documents while others send us HTML emails (with all our invoice information in it), and some others even send us links to the invoices.
The easiest option is to create the document in HTML and send users a link to that document (secured obviously). This would allow users to view the invoice whenever they want (and from any device with a browser) and would also allow them to print from the browser if needed. This method also generates traffic to your website which is usually also beneficial to the business.
What we've done in the past is create a link to the file on the website (secured) so that they can view it in the browser, and then have a button to download the invoice (which just downloads a PDF version of that webpage generated with one of the PDF Conversion tools listed above - currently wkhtmltopdf).
In my opinion, the best method would be to combine all delivery approaches into one. Send an email with the file information in the email's HTML content and attach a PDF of that file. Inside the header portion of the email content (at the top of the email), send a link giving the recipient direct access to the webpage containing all the information (located within their account in your secure portal). This allows them to view it in the browser just in case they can't view it properly in their email and in case they don't have a PDF viewer (I know it's rare nowadays, but you'd be surprised just how many people out there have outdated systems - we still need to send faxes to some clients because they still don't have emails; yes still now in 2017, sigh...). On your website, also provide them with a download link for the PDF document (which would again just take the page they are currently on and convert it into a PDF and automatically download it through the browser).
I hope this helps!
I would like to add another option in the probable solution list. Aspose.PDF Cloud API also offers features to convert HTML to PDF. It provides SDKs for all popular programming languages.
PHP sample code for HTML to PDF conversion:
//Html file with resource files
$name = "HtmlWithImage.zip";
$html_file_name = "HtmlWithImage.html";
$height = 650;
$width = 250;
$src_path = $name;
$response = pdfApi->getHtmlInStorageToPdf($src_path, $html_file_name, $height, $width);
print_r($response);
echo "Completed!!!!";
I work with Aspose as developer evangelist.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With