[reportlab-users] Extra Canvas Translation?

Carl waldbie at verizon.net
Sun Sep 18 12:41:23 EDT 2005


On Sunday 18 September 2005 7:22 am, Robin Becker wrote:
> Carl wrote:
> > I have been experimenting with the interaction between the flowable
> > elements of the Platypus engine and the non-flowing drawing routines of
> > pdfgen.  In one of my examples, I am rotating a page so it will print out
> > landscape-wise. I place a non-flowing banner on it with the PageTemplate
> > event hooks, and I place some paragraph text on the page with the
> > Platypus engine.
> >
> > However, I also attempted to place some non-flowing content on the page
> > by use of a variation on the Macro flowable.  I was puzzled when it did
> > not show up as expected, but then I decided to print out the absolute
> > coordinates of the canvas origin in each case.  To my surprise, the
> > origin has been translated off the page!  Can anyone help me understand
> > why this is happening?  My example program follows:
>
> ....
>
> the flowable.drawOn action is called by the frame with the current frame
> position as arguments. In order to allow 'normal' floables to use self
> relative coordinates the 'standard' drawOn method translates the origin
> to the current position in the frame which calls the drawOn method when
> adding flowables. It should be relatively easy to create a new drawOn
> method which doesn't do the translation and use that in your macro.
> Alternatively you can start your draw method with
> self.canv.restoreState() to remove the translation and finish it with a
> fake self.canv.saveState() to provide drawOn with something to restore.
Robin,

Thanks, that makes perfect sense once you explained it.  I decided that the 
easiest thing to do was to move all my initial transformations into a single 
function.  The, in the macro command, I use the canvas to saveState, 
restoreDefaults, apply my original transforms, do the non-flowable printing, 
and restoreState.

Thanks,
Carl Waldbieser


More information about the reportlab-users mailing list