Reportlab Paragraph text offset with respect to Paragraph bounding box

103 Views Asked by At

I'm trying to use reportlab's Paragraph (reportlab.platypus.Paragraph) in a document with bottomup=0 (I'm using reportlab's canvas), and for some reason the text is starting at the end of the Paragraph's bounding box.

# I'm doing it like this
p_style = ParagraphStyle("Desc", fontName="Times-Roman", fontSize=12, backColor="yellow")
par = Paragraph("Here goes the text", p_style)
par.wrapOn(c, w, h)
par.drawOn(c, x, y)

The resulting pdf has a yellow bounding box in the expected place (at the x and y coordinates given at drawOn, but the text starts at the bottom of the yellow bounding box (at the height where you'd expect the last line to be) and just flows downward, leaving the box's walls.

I'm guessing this weird behavior may have something to do with the bottomup=0 setting (my document coordinates go from top to bottom instead of the default bottom to top), cause I had similar coordinate issues with images due to the same setting.

However, I can't seem to find a way to correct for this offset (I can get the Paragraph's bounding box size from the wrapOn function, but there doesn't seem to be any text offset parameter in the paragraph so as to pull the text up towards the place it's supposed to start).

Edit: I made some tests and indeed this only happens when bottomup=0 (the paragraph bounding box expands upwards instead of downwards, which makes the text appear as if it started at the bottom). However, I still can't figure out how to correct for that (and the whole script and its measurements are all made for bottomup=0 so it's not as if I can just switch that coordinate system).

0

There are 0 best solutions below