I'm looking for a good, open source, PDF generator/library that will convert html (with styling etc.) into a PDF file.
Requirement:
Yes I have tried searching for this myself - I've tried many "solutions" that I've found on Google etc. None yet satisfy me. Many seem incomplete, buggy or don't work well on GAE. So I figured I would appeal to the StackOverflow community for opinions or suggestions.
PDF Convert - Convert Documents - Google Workspace Marketplace. Convert your Documents to PDF and vice-versa format for free. This software is free to use and will convert your documents into PDF and vice-versa within seconds.
Google App Engine is a cloud computing platform for developing web-based applications. With this tool developers are able to code applications without worrying about server management or hardware configurations because this is managed by the engine.
App Engine standard environment pricing. Apps in the standard environment have a free tier for App Engine resources. Any use of App Engine resources beyond the free tier incurs charges as described in this section.
Follow these easy steps to convert a file to PDF using the Acrobat online PDF converter: Click the Select a file button above or drag and drop a file into the drop zone. Select the document you want to convert to PDF. Watch Adobe Acrobat do its PDF conversion magic.
For HTML/image to PDF I use the Python library http://www.xhtml2pdf.com/ which uses Pisa, Reportlab, pyPdf, and html5lib running on GAE. I have been using it to generate very nice article PDFs with embedded images and once I figured out how to get the page size correct I have found this to be a very good library.
You will need the xhtml2pdf library and it's dependencies: https://github.com/chrisglass/xhtml2pdf
I threw together some example Python code and put it in this pastebin: http://pastebin.com/FFEZjNs3
The pdf_data you get at the end is the binary PDF file data. The html_data you give to pisa is really any string containing an HTML document.
There are some recommended things to include in your HTML to get a well formatted PDF output. Here is an example HTML document similar to the base template I use. Note the author meta field and the @page CSS: http://pastebin.com/q1wRm9nJ
Here are the docs about the compatible CSS and HTML: https://github.com/chrisglass/xhtml2pdf/blob/master/doc/usage.rst#supported-css-properties
You can include images using either the URL of the external image or you can use a dataUri and xhtml2pdf has a function for creating these "pisa.makeDataURI()".
Hopefully that helps.
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