[reportlab-users] PDF without file

Robin Becker robin at reportlab.com
Tue May 30 13:07:59 EDT 2006


François Pinard wrote:
> [Michael Hipp]
>>> [Andy Robinson]
> 
>>> Yes, pass a CStringIO or other file like object to the filename 
>>> argument either when constructing a canvas or a doctemplate, and it 
>>> will put the file in that.
> 
>> Thanks, looks like that will work perfectly.
> 
> Hi, people.  I did not follow the thread and may be fully out of 
> context, so take me with a few grains of salt :-).
> 
> Contents of a CStringIO may not be Unicode (unless Python changed 
> recently).  Now that Reportlab is Unicode-aware, one may sometimes have 
> to resort to the slower StringIO.
> 
Being in utterly duh Homer mode I completely forgot that there is indeed an 
existing string output for the code in the canvas.
Just use

pdf = c.getpdfdata()

This won't help if you're using platypus as the save stuff goes on there in the 
build method. However, there's a hack that lets you avoid the actual save eg

doc._doSave = 0
doc.build(story)
pdf = doc.canv.getpdfdata()

the getpdfdata method indicates you shouldn't do anything to the canvas after 
calling it.
-- 
Robin Becker


More information about the reportlab-users mailing list