[reportlab-users] (Solved) Calling canvas.save() repeatedly causes multi-page PDF irregularities

Tim Meneely meneelyt at gmail.com
Tue Aug 2 09:04:23 EDT 2016


Greetings,

I think I've figured this out, but am sharing it for posterity.

I'm using Django & ReportLab open source to manage conference registration
for ~2000 people, sharing the work among several registrars. I use Chrome
and have had no problems, but on some multi-page reports, another registrar
using Firefox could only see the first page.

Ultimately I realized I was calling canvas.save() on every page, when I
should be calling it once per report - that is, I should have something
like:
def report_doorsignsRL(**kwargs):
    dorms = Building.objects.all()
    buffer = StringIO()
    c = canvas.Canvas(buffer, pagesize=landscape(LETTER))
    for dorm in dorms:
        c.rect(0.25*inch, 0.65*inch, PAGE_WIDTH-0.5*inch,
PAGE_HEIGHT-0.9*inch, True, False)
        c.showPage()
        #c.save() # I was calling save() after every showPage() and it
caused Firefox problems
    c.save() # Only one save() per report seems correct
    pdf = buffer.getvalue()
    return pdf

The odd part is it worked OK in Chrome and Acrobat - although with the new
version I seem to be getting faster and smaller PDFs, so maybe it caused
problems there too and I just didn't see them.

In reviewing the docs, I don't see much in terms of multi-page, so I
thought this might be useful to share.

Tim Meneely
Pittsburgh PA USA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20160802/936d7d58/attachment.html>


More information about the reportlab-users mailing list