[reportlab-users] streaming PDF content

Thomas Blatter bebabo at swissonline.ch
Wed Aug 3 05:09:27 EDT 2005


Hi,

BasicDocTemplate constructor has a canvasmaker argument, with this you 
can control the canvas it uses and prevent saving of the template to a file.

A canvasmaker i made to get a multitude of templates in a single file:

gcanvas = None
gcanvas_save = None
def canvasmaker(*args,**kw):
     global gcanvas, gcanvas_save
     if not gcanvas:
         from reportlab.pdfgen import canvas
         gcanvas = apply(canvas.Canvas,args,kw)
         gcanvas_save = gcanvas.save
         gcanvas.save = lambda:None # no need to make it an
                                    # instancemethod, we do... nothing
     return gcanvas

So actually the .save() which the .build() of the template does is 
overriden with 'doing nothing', so you can .getpdfdata() on the canvas 
after the .build().

Regards
Thomas Blatter

Nicholas Wieland wrote:
> Hi *, I think I _finally_ got reportlab :)
> My problem now is that using platypus with BaseDocTemplate I'm not able 
> to "stream" the PDF on the web anymore.
> Basically I was doing something like
>  
>   return canvas.getpdfdata ()
>  
> after setting some headers.
> With BaseDocTemplate I can doc.build () the document, but actually I 
> didn't find a way to have the same effect of getpdfdata ().
> I also tried doc.canv.getpdfdata () but the pdf is empty.
> Suggestions ?
> 
> ------------------------------------------------------------------------
> *Yahoo! Messenger* 
> <http://us.rd.yahoo.com/mail_it/taglines/*http://it.beta.messenger.yahoo.com>: 
> chiamate gratuite in tutto il mondo
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users


More information about the reportlab-users mailing list