[reportlab-users] a replicated canvas?

Robin Becker robin at reportlab.com
Tue Sep 18 08:27:17 EDT 2007


Jon Bradley wrote:

>

> On Sep 18, 2007, at 7:19 AM, Robin Becker wrote:

>

>> You can create a form and place that multiple times on the same pdf

>> canvas.

>>

>> So if you have a pdfgen.canvas.Canvas instance c

>>

>> you can do

>>

>> c.beginForm('myform')

>> c.saveState()

>> c.draw...... other ops etc etc

>> c.rstoreState()

>> c.endForm()

>>

>> to define the form and later

>>

>> c.doForm('myform')

>>

>> you can repeat the doForm in different userspace transformations to

>> get the form in different places on the page.

>

> Ah... that sounds great. But then what do I do about modifying that text

> field within "c" during my loops for placing it on the page. Can I

> modify the form after the fact - ie, c.myform.value = something, then

> process the doForm method at the current x,y position?

>

> Thanks a ton for the help. I'm quite a newbie on reportlab (and it's

> been years since I've scripted in Python), so bear with me. ;)

>

> best,

>

> jon

......
No you should use the form for the fixed part assuming it's not trivial like a
single image. I'm fairly sure that drawInlineImage does each image separately,
but drawImage creates an image xobject (like a form) so can be re-used without
too much memory usage.

If you know the relation between the form and the text you want to draw you can
just use the same user space and do doForm()....drawString in the same userspace
and hope to get the text at the same relative location each usage. I suspect if
you're just doing the same image use

for x,y,text in myIterator():
drawImage('image.gif',x,y)
drawString(text,x+dx,y+dy)

where dx and dy are set up by you to position the start of the text.
--
Robin Becker


More information about the reportlab-users mailing list