[reportlab-users] Re: rotate bug? or I' missing somethings...

Robin Becker robin at reportlab.com
Fri Oct 20 05:57:41 EDT 2006


pier carteri wrote:
> Sorry....:-P
> here are the files !
> 
> On 10/20/06, pier carteri <pier.carteri at gmail.com> wrote:
>>
>> Hi to the list,
>> first of all, I want to say a big thank you to all the Reportlab guys.
>> Your libs rocks and simplify my day-to-day developer life a lot!
>> It is really a pleasure to create pdf with this tecnology!
>>
>> Now back to the subject of this mail:
>> probably I' ve not undestand somethings of the rotate method in canvas
>> object (or maybe is a bug ).
>> Consider the code
>>
>> from reportlab.pdfgen import canvas
>> import reportlab.lib.pagesizes as ps
>> c = canvas.Canvas("test.pdf")
>> c.setFont("Times-Roman", 60)
>> c.drawCentredString(ps.A4[0]/2, ps.A4[1]/2, "Confidential")
>> c.save()
>>
>>
>> This create the pdf test_1.pdf as expected. Now if I add a rotate:
>>
>> from reportlab.pdfgen import canvas
>> import reportlab.lib.pagesizes as ps
>> c = canvas.Canvas("test.pdf")
>> c.setFont("Times-Roman", 60)
>> c.rotate(45)
>> c.drawCentredString(ps.A4[0]/2, ps.A4[1]/2, "Confidential")
>> c.save()
>>
>> I expect to have the same output but with the string rotate of 45, but I
>> obtain the test_2.pdf output
>>
>> What's wrong?
>>
>> Thank you!
>>
>> Pier
......

When you rotate the canvas you are actually rotating the whole thing about its 
origin which in this case is near the bottom left hand corener of the page. If 
you want to rotate your text then you should consider doing this sequence instead

#untested
c.saveState()
c.setFont("Times-Roman", 60)
c.translate(ps.A4[0]/2, ps.A4[1]/2)
c.rotate(45)
c.drawCentredString(0,0, "Confidential")
c.restoreState()

in place of the
 >> c.setFont("Times-Roman", 60)
 >> c.rotate(45)
 >> c.drawCentredString(ps.A4[0]/2, ps.A4[1]/2, "Confidential")
-- 
Robin Becker


More information about the reportlab-users mailing list