It's child easy, but not googleable yet. I used reportlab - a handy, pure-python pdf library. Here are the steps:
- Checkout reportlab into your app directory
svn co http://www.reportlab.co.uk/svn/public/reportlab/trunk \
reportlab - Write some pdf-generation code, like
The key is the canvas instantiation. The constructor takes a file-like object and writes into it. You might have noticed that the code is heavily inspired by this tutorial. The only difference is the creation of canvas.import wsgiref.handlers
from google.appengine.ext import webapp
from reportlab.pdfgen import canvas
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'application/pdf'
p = canvas.Canvas(self.response.out)
p.drawString(100, 750, "Hey, it's easy!.")
p.showPage()
p.save()
def main():
application = webapp.WSGIApplication([('/', MainPage)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == "__main__":
main() - That's it. See? I said it was easy. You can run the dev_appserver or upload it to Google in order to see the results.
8 comments:
Ha! Brilliant! :-)
Thank you. This was exactly what I was looking for.
I was not able to download ReportLab from their svn site. I could download the ReportLab Toolkit in zip form for Windows. Initially, I download the .tgz version. But it includes compiled (pyc) files that didn't seem to work on Windows. I switched to the zip distribution and it worked; it generated the sample PDF.
http://www.reportlab.org/subversion.html
svn co https://www.reportlab.co.uk/svn/public/reportlab/trunk
Note in Aug 2008: due to recurring problems with our ISP which we have been able to resolve, port 80 into this server is no not working; please use https as indicated above.
Its not working for me...i am getting the error no such module found...i am using django, in addition i created a symbolic link of reportlab in my application directory...help greatly appreciated...
Thanks Just what I was looking for.
Thanks, this helped a lot!
Great, its eazy and it just works
Post a Comment