Nikhil Jain
Nikhil Jain

Reputation: 193

HTML to PDF conversion in app engine python

My website has a lot of dynamically generated HTML content and I would like to give my website users a way to save the data in PDF format. Any ideas on how it can be done? I tried xhtml2pdf library but I couldn't get it to work. I even tried reportlibrary but we have to enter the PDF details manually. Is there any library which converts HTML content to PDF and works on app engine?

Upvotes: 2

Views: 977

Answers (1)

Dmytro Sadovnychyi
Dmytro Sadovnychyi

Reputation: 6201

You need to copy all dependencies into your GAE project folder:

html5lib 
reportlab
six 
xhtml2pdf

Then you can use it like this:

from xhtml2pdf import pisa
from cStringIO import StringIO

content = StringIO('html goes here')
output = StringIO()
pisa.log.setLevel('DEBUG')
pdf = pisa.CreatePDF(content, output, encoding='utf-8')
pdf_data = pdf.dest.getvalue()

Some useful info that I googled just for you:

http://www.prahladyeri.com/2013/11/how-to-generate-pdf-in-python-for-google-app-engine/ https://github.com/danimajo/pineapple_pdf

Upvotes: 2

Related Questions