8

Using ReportLab, I want to render a block of text with a large font size. Right now, my code places the text within a Paragraph so it can be word wrapped. However, the text turns out crammed together when rendered.

It seems like the height I specified for the Paragraph object is not being taken into account. Is there an attribute for Paragraph that I can add to fix this?

My Code Below:

from reportlab.pdfgen import canvas
from reportlab.lib.units import inch 
from reportlab.platypus import Paragraph
from  reportlab.lib.styles import ParagraphStyle
from reportlab.lib.enums import TA_CENTER

doc = canvas.Canvas('test.pdf')
p = ParagraphStyle('test')
p.textColor = 'black'
p.borderColor = 'black'
p.borderWidth = 1
p.alignment = TA_CENTER
p.fontSize = 100

para = Paragraph("THIS IS A REALLY LONG AND BIG STRING OF TEXT RIGHT HERE!!!!!", p)
para.wrapOn(doc,1200,1000)
para.drawOn(doc, 0.5*inch, 6*inch)
doc.save()
1

1 Answer 1

7
+50

The answer is to set the leading attribute to 120:

p.leading = 120

By default, a style has a fontSize of 10 with a leading value of 12. The leading parameter specifies the distance down to move when advancing from one text line to the next.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.