[reportlab-users] Rotated paragraph/document with ReportLab (vertical text)
Robin Becker
robin at reportlab.com
Thu Oct 25 12:54:08 EDT 2012
I'm not sure exactly why you want to do this, but the code below is a start
you will need to tweak the translate here to get exactly what you want as we
will obviously be rotating about a place that's not exactly clear ie the center
of the top line.
#########################
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()
self.canv.translate(0,0)
self.canv.rotate(90)
Paragraph.draw(self)
self.canv.restoreState()
style = getSampleStyleSheet()
normal = style["Normal"]
normal.alignment = TA_CENTER
normal.fontName = "Helvetica"
normal.fontSize = 15
pdf = SimpleDocTemplate("rotatedpara.pdf", pagesize = (80, 250),
rightMargin=10, leftMargin=10, topMargin=20,bottomMargin=20)
story = []
text = "I really need this to be wrapped and vertical!"
para = RotatedPara(text, normal)
story.append(para)
pdf.build(story)
#########################
On 25/10/2012 14:16, Jesus Sanchez-Palencia wrote:
> Hi!
>
> I'm trying to get something like the following snippet to actually
> draw this document rotated by 90 degrees. The pagesize is already the
> way I want it in the end, but the text is still horizontal. How can I
> rotate the text making it vertical?
> What I want in the end is something similar to calling
> canvas.rotate(90) and then canvas.drawString(), but I want to take
> the advantage of word wrapping from Paragraph...
.........
--
Robin Becker
More information about the reportlab-users
mailing list