PDF Generation

439 views
Skip to first unread message

David Cifuentes

unread,
May 12, 2008, 9:36:59 PM5/12/08
to Google App Engine
Hi all,

I'm trying to add to my app engine project functionality for exporting
as a PDF file. I'm trying to use the ReportLab library
http://www.reportlab.org/downloads.html and I'm also following the
tutorial in http://www.devshed.com/c/a/Python/Python-for-PDF-Generation/
mixed with the example in http://www.djangoproject.com/documentation/outputting_pdf/

But when I save the file I get the following error inside the PDF
document:

Traceback (most recent call last):
File "C:\Archivos de Programa\Google\google_appengine\google
\appengine\ext\webapp\__init__.py", line 499, in __call__
handler.get(*groups)
File "C:\ecv.eforcers.com\ecv\src\handler\fin.py", line 40, in get
pdf.save()
File "C:\ecv.eforcers.com\ecv\reportlab\pdfgen\canvas.py", line 877,
in save
self._doc.SaveToFile(self._filename, self)
File "C:\ecv.eforcers.com\ecv\reportlab\pdfbase\pdfdoc.py", line
218, in SaveToFile
f = open(filename, "wb")
File "C:\Archivos de Programa\Google\google_appengine\google
\appengine\tools\dev_appserver.py", line 736, in __init__
raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: wb

It looks like I'm violating the condition to write on the filesystem,
even if I try the http response as a file.

Here is my code...

import cgi
import wsgiref.handlers
import logging

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db

import os
from google.appengine.ext.webapp import template

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import cm, mm, inch, pica

from django.http import HttpResponse

class FinHandler(webapp.RequestHandler):
def get(self, id_persona=None):
logging.debug("Entrando a generar el PDF para la persona %s",
id_persona)

# Create the HttpResponse object with the appropriate PDF headers.
self.response.headers.add_header("Content-Type", "application/
pdf")
self.response.headers.add_header("Content-Disposition",
"attachment; filename=cv.pdf")
# Create the PDF object, using the response object as its "file."
pdf = canvas.Canvas(self.response)
# Draw things on the PDF. Here's where the PDF generation happens.
# See the ReportLab documentation for the full list of
functionality.
pdf.setFont("Courier", 60)
pdf.setFillColorRGB(1, 0, 0)
pdf.drawCentredString(letter[0] / 2, inch * 6, "CLASSIFIED")
pdf.setFont("Courier", 30)
pdf.drawCentredString(letter[0] / 2, inch * 5, "For Your Eyes
Only")
# Close the PDF object cleanly, and we're done.
pdf.showPage()
pdf.save()

Please, if any of you have implemented this functionality with
ReportLab or a different library I would appreciate any help. Thanks

David C

David Cifuentes

unread,
May 12, 2008, 9:51:17 PM5/12/08
to Google App Engine
Sorry!!

Didn't search enough. I found the answer in:

http://konryd.blogspot.com/2008/04/outputting-pdfs-with-google-app-engine.html

I hope this helps people with the same problem...

David C.

On 12 mayo, 20:36, David Cifuentes <david.cifuen...@eforcers.com>
wrote:
> Hi all,
>
> I'm trying to add to my app engine project functionality for exporting
> as a PDF file. I'm trying to use the ReportLab libraryhttp://www.reportlab.org/downloads.htmland I'm also following the
> tutorial inhttp://www.devshed.com/c/a/Python/Python-for-PDF-Generation/
> mixed with the example inhttp://www.djangoproject.com/documentation/outputting_pdf/

Aral Balkan

unread,
May 20, 2008, 4:00:04 PM5/20/08
to Google App Engine
Hi David,

Thank you for sharing the link -- looks handy :)

Aral

On May 13, 2:51 am, David Cifuentes <david.cifuen...@eforcers.com>
wrote:
> Sorry!!
>
> Didn't search enough. I found the answer in:
>
> http://konryd.blogspot.com/2008/04/outputting-pdfs-with-google-app-en...
>
> I hope this helps people with the same problem...
>
> David C.
<snip>

Devraj Mukherjee

unread,
May 20, 2008, 6:17:56 PM5/20/08
to google-a...@googlegroups.com
I have also always wondered if its possible to use Google docs to do
this for you. So you upload a doc to the Google doc engine and
download it back as a PDF.

Although GData doesn't yet support downloading of docs programmtically
this could be a viable option for the future.

--
"I never look back darling, it distracts from the now", Edna Mode (The
Incredibles)

Filip

unread,
May 22, 2008, 8:20:56 AM5/22/08
to Google App Engine
Actually, if you could download a Google Doc using GData as PDF, you
could parse it, create a table of contents and insert it in the
original document. That would be cool. The main feature missing from
Google Docs for me is automatic table-of-content generation.

Filip.
> Incredibles)- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Reply all
Reply to author
Forward
0 new messages