[reportlab-users] Damaged pdf file in release mode Compile

Robin Becker robin at reportlab.com
Tue Apr 18 11:46:37 EDT 2006

Thomas Zehbe wrote:
>>> Thomas
>> are all your files being opened in binary mode? It would be a good idea to
>> split the report code off so you can supply it with data directly into the
>> doc generation. So far as I know canvas.save() is OK, but if you're trying
>> to do something special with streams etc then binary mode is essential.
> Hi Robin,
> perhaps I used the wrong words describing my Problem. Talking about "binary 
> stream parts" a mean something like that:
> ...
>  /Length 466 >>
> stream

I mean file streams not the PDF stream objects. If opened as text then we get 
problems because '\n' becomes '\r\n' so the lengths etc go wrong. If you're just 
using BaseDoctemplate then the filename only is used and the canvas should open 
it properly in its save method.

>     for line in cs.fetchall():
>         pos.append((abt, st, art, liefname, abholname, termin, eben, masch))
>     t = Table(pos, (40,20,60,220,220,60,60,80))
>     Story.append(t)
>     try:
>         doc.build(Story)
>     except:
>         ...
>     if os.name == 'nt':
>         os.startfile(docfile)
> ...

>> Another way things can go wrong is if two bits of your app are trying to do
>> things to the document simultaneously. reportlab is not threadsafe.
> I don't think it's a thread problem because the report is called when the user  
> selects a menu entry an the call to the python c-api returns after the report 
> is genrated. This is the call:
>        pValue = PyObject_CallObject(pFunc, pArgs);
> After doing the doc.build  I immediately open the file using acrobat using the 
> startfile command. Is that ok or do I have to finalize the doc in any way?
> Regards
> Thomas

Hopefully the file has been closed by that time.

Robin Becker

More information about the reportlab-users mailing list