PDF writing under GAE

351 views
Skip to first unread message

Arbie Samong

unread,
Apr 4, 2011, 10:08:10 AM4/4/11
to web2py-users
Did anyone figure out how to let users download pdf's that contains
data from the database under GAE? Appengine does not allow file
writing, and most pdf writing libraries I've tried involves
temporarily writing in the disk.

Massimo Di Pierro

unread,
Apr 4, 2011, 10:10:34 AM4/4/11
to web2py-users
does myfpdf require file writing? I did not check? If it does it
should be easy to change it to use a StringIO instead.

Arbie Samong

unread,
Apr 4, 2011, 10:15:04 AM4/4/11
to web2py-users
When trying it out on localhost:8080 using the appengine sdk it
returns an IO error pointing out that writes aren't allowed. I'll be
looking into StringIO, thanks for the tip Massimo

Regards,
Arbie

On Apr 4, 10:10 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:

Arbie Samong

unread,
Apr 4, 2011, 10:30:09 AM4/4/11
to web2py-users
OK what I'm trying right now is something straight out of the wiki:

html = response.render('default/download.html', locals())

class MyFPDF(FPDF, HTMLMixin):
def header(self):
self.set_font('Arial','B',15)
self.cell(0,10, response.title ,1,0,'C')
self.ln(20)

def footer(self):
self.set_y(-15)
self.set_font('Arial','I',8)
txt = 'Page %s of %s' % (self.page_no(), self.alias_nb_pages())
self.cell(0,10,txt,0,0,'C')

pdf.add_page()
pdf.write_html(html)
response.headers['Content-Type']='application/pdf'
return pdf.output(dest='S')

and it gives the error:
RuntimeError: FPDF error: PIL not installed

in which I copied the PIL/ folder from /usr/lib/python2.6/dist-
packages/PIL to the web2py/site-packages/ folder and no effect. PIL is
already installed in the system, as well as in the virtualenv I'm
using.

Regards,
Arbie

Arbie Samong

unread,
Apr 4, 2011, 10:35:19 AM4/4/11
to web2py-users
OK update, PIL is being required because I have an image tag in my
view, I removed the tag and the pdf was downloaded fine. Would love to
have images written properly, though.

Regards,
Arbie

Arbie Samong

unread,
Apr 4, 2011, 11:21:59 AM4/4/11
to web2py-users
Follow-up question, how do I get PIL to be recognized as installed? I
tried easy_install on the whole system, then on the virtual env, then
copying the PIL/ folder to site-packages, but nothing seems to work.

Thanks,
Arbie

Martín Mulone

unread,
Apr 4, 2011, 11:56:54 AM4/4/11
to web...@googlegroups.com
Perhaps changing this line in fpdf:


with this one work

from google.appengine.api import images


2011/4/4 Arbie Samong <phe...@gmail.com>
Message has been deleted

howesc

unread,
Apr 4, 2011, 3:11:36 PM4/4/11
to web...@googlegroups.com, mar...@tecnodoc.com.ar
hopefully not a red herring, but google gave us gifts last week, one of them was file "reading" and "writing" from the blobstore: http://googleappengine.blogspot.com/2011/03/announcing-app-engine-143-release_30.html

i have not looked at how to connect things to it, but might help here.

cfh

Arbie Samong

unread,
Apr 5, 2011, 12:52:51 AM4/5/11
to web2py-users
@martin - that helped me passed the try-except block at the beginning,
but when the Image module is used on the other parts of the code it
went haywire. I'll look into it probably more changes to make it adapt
with GAE.

@howesc - I was able to make it work without using the file system
read and write, but this is like heaven sent :)

On Apr 5, 3:11 am, howesc <how...@umich.edu> wrote:
> hopefully not a red herring, but google gave us gifts last week, one of them
> was file "reading" and "writing" from the blobstore:http://googleappengine.blogspot.com/2011/03/announcing-app-engine-143...

Martín Mulone

unread,
Apr 5, 2011, 6:19:40 AM4/5/11
to web...@googlegroups.com
Well I browse the code of fpdf.py and pil is only using to check is the file is and image format, I think is easy to do to support gae, changing in gae to api or make the check like IS_IMAGE from web2py.

Anyways there are other tools you can use to write pdf reports like PISA, Reportlab.

2011/4/5 Arbie Samong <phe...@gmail.com>

contatog...@gmail.com

unread,
Apr 5, 2011, 8:47:50 AM4/5/11
to web...@googlegroups.com
There's this plugin for web2pyhttps://github.com/lucasdavila/appreport
__________________________________ ___________
Gilson Filho

Massimo Di Pierro

unread,
Apr 5, 2011, 9:15:20 AM4/5/11
to web2py-users
It would be nice if fpdf were to work on GAE out of the box. Moreover
I think PIL is available on GAE.

On Apr 5, 5:19 am, Martín Mulone <mulone.mar...@gmail.com> wrote:
> Well I browse the code of fpdf.py and pil is only using to check is the file
> is and image format, I think is easy to do to support gae, changing in gae
> to api or make the check like IS_IMAGE from web2py.
>
> Anyways there are other tools you can use to write pdf reports like PISA,
> Reportlab.
>
> 2011/4/5 Arbie Samong <phek...@gmail.com>

andrej burja

unread,
Apr 6, 2011, 2:25:26 AM4/6/11
to web2py-users
hi

pyftpdf (included in web2py) does not have unicode support
does anybody know are there some unicode problems in reportlab too?
maby font problems?

i would like to see code example for reportlab on gae (since the
example in the book does not work :)

andrej


On Apr 5, 3:15 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> > Expert4Solution:http://www.experts4solutions.com/e4s/default/expert/6http://www.cvsta...
Reply all
Reply to author
Forward
0 new messages