31

I'd like to create an application that would run on Google's appengine.

However, this application needs to be able to generate PDFs dynamically.

How could I do this?

David
  • 17,673
  • 10
  • 68
  • 97
carrier
  • 32,209
  • 23
  • 76
  • 99

4 Answers4

25

You can use the reportlab library to generate a PDF from Python. You can just include the ReportLab files in with your application's code, or you can include a zip archive of the ReportLab code, and insert it into your application's sys.path.

Paul Fisher
  • 9,618
  • 5
  • 37
  • 53
  • Does reportlab actually work under AppEngine? I was under the possibly-mistaken impression that it uses C extensions, which AppEngine doesn't allow. – Robert Rossney Jan 08 '09 at 21:38
  • Reportlab is pure Python, but it uses PIL for images, so you won't be able to use it for PDFs containing images. – Nick Johnson Jan 09 '09 at 11:13
  • 3
    GAE now supports PIL so that should not be a problem. – Federico Builes Jun 04 '09 at 15:32
  • Does this actually work? Reading the reportlab API, you seem to have to write to a file. That's not possible on GAE. – Gareth Simpson Aug 09 '09 at 08:22
  • 7
    You can write to any file-like object, meaning that you could write to, say, `response.out`. For example, http://konryd.blogspot.com/2008/04/outputting-pdfs-with-google-app-engine.html – Paul Fisher Aug 09 '09 at 11:39
  • Thanks. Note, I needed the fix referred to by @varun below – Gareth Simpson Aug 29 '09 at 16:21
  • Just getting into this today, found a good primer by Nick Johnson on his blog http://blog.notdot.net/2010/04/Generating-PDFs-on-App-Engine-Python-and-introducing-Mapvelopes – Campey Jan 27 '12 at 07:02
7

To overcome the number-of-files limit in google appengine, you could package your reportlib in a zip file and use it. Be sure you check out this issue i bumped into..

http://code.google.com/p/googleappengine/issues/detail?id=1085

Also, you can use pisa, htmllib and pyPdf to generate the pdf using html templates.

All the best.

varun

varun
  • 569
  • 7
  • 10
3

I would recommend PyFPDF, which is a pure-Python port of the lightweight yet highly powerful PHP FPDF library. It is hardly a few dozen kilobytes.

See http://code.google.com/p/pyfpdf/

Louis LC
  • 5,454
  • 1
  • 17
  • 13
3

Google has a new "Conversion API" that may solve all your problems. Here's a description from the site:

The App Engine Conversion API converts documents between common filetypes using Google's infrastructure for efficiency and scale. The API enables conversions between HTML, PDF, text, and image formats, synchronously or asynchronously, with an option to perform optical character recognition (OCR).

Eric Nguyen
  • 40,312
  • 4
  • 25
  • 31