[reportlab-users] Run time error with version 3.4

lizhe Xu xulz2004 at yahoo.com
Wed May 24 08:45:42 EDT 2017

Hi Robin,
Sorry for the late response, I was out of office since last Friday. The script was developed by my colleague and I'm the user. I plan to learn Python but still has not got time to do so.
How to find the version of reportLab installed on a Mac? I wonder if I can uninstall the version 3.4 from my computer, and re-install the same version as my colleague to make it work.
BTW, I changed the statement which caused the runtime error from c.save() to c.showPage(). As a result, the script was completed and the pdf generated is a several-page file, but totally empty without anything drawed. I have to say that I don't quite understand Python, and the script. It may need to modify other statements as well to make it work correctly. 
Thank you very much.


      From: Robin Becker <robin at reportlab.com>
 To: lizhe Xu <xulz2004 at yahoo.com>; reportlab-users <reportlab-users at lists2.reportlab.com> 
 Sent: Friday, May 19, 2017 4:51 AM
 Subject: Re: [reportlab-users] Run time error with version 3.4

I don't know where the idea arose that you can repeatedly save a canvas object, 
but more than one person has tried it see


The Canvas contains many structured objects including a PDFDocument instance. 
That is the class that causes your error. When you save the Canvas lots of 
structures get changed. That means the Canvas is no longer valid and should be 
thrown away.

To save individual pages the showPage method should be called.

So  like

canv = Canvas(...)
for info in mystuff:

should really be

canv = Canvas(...)
for info in mystuff:

this may or may not suit if the number of pages is high, but we don't have a 
method which incrementally writes the document out. It might have worked in the 
past if you were lucky, but it was never intended to be so.

On 18/05/2017 20:30, lizhe Xu wrote:
> I called my colleague who developed the Python code and he is using the script daily without any error. The only difference between his and mine is I'm using the newer vision of reportLab.
> Yes, the script tries to save a canvas for each loop by adding a new page. Attached two files are the results of running the script from different data sets: WithSave.pdf was generated by my colleague with the original script and old version of reportLab; WithoutSave.pdf was generated from my computer by commenting out the line 546 c.save().
> So, I guess the implementation of the new SaveToFile may differ in the different versions. But my goal is to run the script on my computer without bothering my colleague by emailing data to him anymore. So I wonder if there is a method other than save() will do the magic for me.
> Thanks.

Robin Becker

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20170524/4b4dcff5/attachment-0001.html>

More information about the reportlab-users mailing list