(Solved) Calling canvas.save() repeatedly causes multi-page PDF irregularities

Tim Meneely <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CACgdiuqh5ZUNKhw=7QNYKNmak8zkbNunB72M7Dcib4zqbK+FJA@mail.gmail.com>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.