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
> 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.
> 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
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.
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.
On 21 mei, 00:17, "Devraj Mukherjee" <dev...@gmail.com> wrote:
> 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.
> On Wed, May 21, 2008 at 6:00 AM, Aral Balkan <aralbal...@gmail.com> wrote:
> > 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!!