Search code examples
pythonhtmlreportlab

Breakline in Paragraph Reportlab


I am trying to add a breakline in Paragraph in Reportlab. While some HTML tags like works,
causes this exception:

caused exception paraparser: syntax error: No content allowed in br tag

This is where I wrap my text:

  style = ParagraphStyle(
      name='Normal',
      spaceAfter=40,
      fontName='Times-BoldItalic',
      fontSize=18,
  )

text=Paragraph(f"<p> <b>{df.set_index('concat').loc[i]['Title']}</b> <br> Some more text </p>", style=style)

Solution

  • Use <br/> instead of <br>.

    Using <br> raises a ValueError: paraparser: syntax error: No content allowed in br tag


    If using <br/> does not fix the issue then use a closing tag <br/> along with <br>.

    Try:

    text=Paragraph(f"<p> <b>{df.set_index('concat').loc[i]['Title']}</b> <br> <br/>Some more text </p>", style=style)