[reportlab-users] rotate page

Tim Roberts timr at probo.com
Thu Dec 4 12:54:40 EST 2008


giulia cherubini wrote:

>

> can anyone help me?

> I'm trying to rotate a page because values I have to print overflow.

> When i put 'can.rotate(90)' values...go outside paper and disappear.

> I'm not sure to have correctly understand how to use the rotate

> method, andwhere exactly put it for rotate the whole page...and see it!!!

> I attach my little sample (wx_python, postgres)


Sometimes I have to draw these things out on a whiteboard so that they
make sense. There is a tendency to believe that rotating the canvas
also moves the origin, but it does not.

In the default case, the origin for a Postscript page is the lower left
corner, with X increasing to the right, and Y increasing upwards:

+----+
+Y | |
| |
^ | |
| | |
+----+
0,0 --> +X

When you rotate the canvas by 90 degrees, it is rotating it AROUND that
origin. So, after a 90 degree rotation, the origin is at the lower
right of the page, but it's still set up so that X increases to the
right and Y increases upwards. That means that your entire canvas now
needs to use negative X coordinates:

+---------+ +Y
| |
| |
+---------+
-X <-- 0,0 --> +X

So, to get things back to the same condition you had before, you need to
move the origin pagewidth units to the left, using canvas.transform, but
remember that the new page width is what USED to be the page height!

canv.rotate( 90 )
canv.transform( -pagewidth[1], 0 )

(It is possible that I rotated this 90 degrees in the wrong direction,
but the same principles apply.)

If you just need landscape, the easiest thing is to change the page size:
from reportlab.lib.pagesizes import LETTER, landscape
canv = canvas.Canvas( 'xxxx.pdf', pagesize = landscape(LETTER) )

This is cheating a little bit, because it doesn't actually change the
orientation of the page, but most people run the Acrobat reader with
"auto-rotate and center" set, which will automatically set the printer
to landscape for printing.

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the reportlab-users mailing list