[reportlab-users] merging canvas

Andy Robinson andy at reportlab.com
Fri May 12 04:40:49 EDT 2006

François wrote:
> Hello,
> It's possible to merge 2 canvas make with reportlab, before or after 
> canvas.save() ?
> pdf1 = canvas.Canvas("test1.pdf")
> pdf2 = canvas.Canvas("test2.pdf")
> pdf1 += pdf2

No.  To make documents "additive", you would need to refactor your code 
so that the same canvas gets passed into two document-making functions; 
and certain things like the page number would not be reset.

However, the module reportlab/pdfgen/pycanvas.py contributed by Jerome 
Alet might help.  It's basically a 'recorder'; from the docstring...

"""pycanvas.Canvas class works exactly like canvas.Canvas, but you can
call str() on pycanvas.Canvas instances. Doing so will return the
Python source code equivalent to your own program, which would, when
run, produce the same PDF document as your original program.

Generated Python source code defines a doIt() function which accepts
a filename or file-like object as its first parameter, and an
optional boolean parameter named "regenerate". """

Our commercial PageCatcher product lets you merge PDFs after they have 
been made, but merging before creation is a lot more flexible and faster.

Hope this helps

- Andy

More information about the reportlab-users mailing list