Paragraph Line Breaks

23 views
Skip to first unread message

Emily Jamieson

unread,
Jan 12, 2023, 7:01:59 AM1/12/23
to reportlab-users
Hi,

I'm trying to create a paragraph with several line breaks. The line breaks work, but I end up with blank lines at the beginning of the paragraph, the same number of blank lines as there were line breaks in the paragraph (see attached example, if there are no line breaks the text is at the top of the box as expected). Do you have any ideas on how I could remove these unwanted blank lines? 🙏

Thank you very much for your help!
Emily

def __init__(self):
    self.packet = io.BytesIO()
    self.can = canvas.Canvas(self.packet, pagesize=A4, bottomup=0)
    self.styles = getSampleStyleSheet()
    self.styles.add(ParagraphStyle(name='Centre', alignment=TA_CENTER))
    self.styles.add(ParagraphStyle(name='Custom', alignment=TA_LEFT, leading=12, spaceBefore=0, spaceAfter=0))
    self.width, self.height = A4
...
p = Paragraph("test<br/>test", style=self.styles['Custom'])
p.wrapOn(self.can, 336, 226)
p.drawOn(self.can, 185, 469)
...

<bound method Flowable.wrapOn of Paragraph(
'caseSensitive': 1
'encoding': 'utf8'
'text': 'test<br/>test'
'frags': [[16.12, (ParaFrag(__tag__='para', _fkind=0, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, link=[], rise=0, text='test', textColor=Color(0,0,0,1), us_lines=[]), 'test')], [0, (ParaFrag(__tag__='br', _fkind=3, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, lineBreak=True, link=[], rise=0, text='', textColor=Color(0,0,0,1), us_lines=[]), '')], [16.12, (ParaFrag(__tag__='para', _fkind=0, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, link=[], rise=0, text='test', textColor=Color(0,0,0,1), us_lines=[]), 'test')]]
'style': <ParagraphStyle 'Custom'>
'bulletText': None
'debug': 0
'width': 336
'_wrapWidths': [336, 336]
'_width_max': 16.12
'height': 24
'_splitLongWordCount': 0
'_hyphenations': 0
'blPara': ParaLines(kind=1, lines=[FragLine(ascent=7.18, descent=-2.07, extraSpace=319.88, fontSize=10, lineBreak=True, maxWidth=336, sFW=0, wordCount=1, words=[ParaFrag(__tag__='para', _fkind=0, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, link=[], rise=0, text='test', textColor=Color(0,0,0,1), us_lines=[]), ParaFrag(__tag__='br', _fkind=3, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, lineBreak=True, link=[], rise=0, text='', textColor=Color(0,0,0,1), us_lines=[])]), ParaLines(ascent=7.18, descent=-2.07, extraSpace=319.88, fontSize=10, lineBreak=False, maxWidth=336, sFW=1, wordCount=1, words=[ParaFrag(__tag__='para', _fkind=0, bold=0, fontName='Helvetica', fontSize=10, greek=0, italic=0, link=[], rise=0, text='test', textColor=Color(0,0,0,1), us_lines=[])])])
) #Paragraph>
Reply all
Reply to author
Forward
0 new messages