How do I find the baseline of a line of text in Reportlab?
H开发者_Go百科ow do I find the baseline for a line of text in Reportlab so I can align other elements on the page with the baseline of the text? I am using canvas.drawString()
for these elements.
The canvas should be thought of as a sheet of white paper with points on the sheet identified using Cartesian (X,Y) coordinates which by default have the (0,0) origin point at the lower left corner of the page.
Furthermore the first coordinate x goes to the right and the second coordinate y goes up, by default.
Knowing x and y coordinates, you can align anything.
from reportlab.pdfgen import canvas
def hello(c):
c.drawString(100,100, "x=100,y=100")
c.drawString(200,200, "x=200,y=200")
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
精彩评论