[reportlab-users] Rotated paragraph/document with ReportLab (vertical text)
Jesus Sanchez-Palencia
jesus at eventick.com.br
Mon Nov 5 22:23:22 EST 2012
Ok,
I can't get this to work as I was expeting it to work... All I want is
to get this snippet:
############################################
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.enums import TA_CENTER
from reportlab.platypus.paragraph import Paragraph
class RotatedPara(Paragraph):
def draw(self):
self.canv.saveState()
Paragraph.draw(self)
self.canv.restoreState()
style = getSampleStyleSheet()
normal = style["Normal"]
normal.alignment = TA_CENTER
normal.fontName = "Helvetica"
normal.fontSize = 15
pdf = SimpleDocTemplate("notrotatedpara.pdf", pagesize = (250, 80),
rightMargin=5, leftMargin=5, topMargin=10, bottomMargin=5)
story = []
text = "Yet another random foo long text!"
para = RotatedPara(text, normal)
story.append(para)
pdf.build(story)
############################################
to work on the very same way it is right now, but with the result
being a rotated pdf. In other words, the end document will be 80 x 250
instead of 250 x 80.
So inside def draw(self) I have tried to self.canv.rotate(90) and then
to translate it as pointed out by Robin Becker, but I can't get the
same behavior. First of all, I don't really get what happens with the
margins from SimpleDocTemplate when we are dealing with the rotated
paragraph. Second, I can't get the translation to work properly. So
far translate(-125, -40) gave me the best results, but this was
somewhat randomly chosen...
Can anyone help me? Are there any other way around this?
Thanks again,
Jesus
On Thu, Oct 25, 2012 at 7:41 PM, Tim Roberts <timr at probo.com> wrote:
> Jesus Sanchez-Palencia wrote:
>> Is there any documentation about what happens to the coordinates after
>> we canvas.rotate(90) everything?
>
> This is all part of PostScript, and it's all from a mathematical point
> of view. A standard canvas has its origin at the bottom left, with X
> increasing to the right, and Y increasing as you go up. For a 250 x 80
> document:
>
> +Y
> (0,80) (250,80)
> +-----------+
> | |
> | canvas |
> | |
> o-----------+ +X
> (0,0) (250,0)
>
> Positive rotation is counter-clockwise about the origin, so rotating by
> 90 degrees changes things so that Y increases to the left, and X
> increases going up. The origin remains the same, so after this
> rotation, all of the Y coordinates in the canvas will be negative.
> That's why you often use a translation when you do a rotation:
>
> +X
> (250,0) (250,-80)
> . - - - +-------+
> : | |
> : | |
> : |canvas |
> : | |
> : | |
> : | |
> +Y . - - - o-------+
> (0,0) (0,-80)
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
More information about the reportlab-users
mailing list