【问题标题】:How do I add breaklines in reportlab PDF in HTML format?如何在 HTML 格式的 reportlab PDF 中添加特征线?
【发布时间】:2021-10-21 11:29:58
【问题描述】:

我正在尝试使用 reportlab 将一些数据放入 PDF 中。我从数据框中获取这些数据。但是,由于一个字段是一个小文本,因此应该有一些断线以使其在 PDF 中可读。

我提取数据的代码部分:

  style_texto4=ParagraphStyle(name='Normal4', fontName='Times-Roman', fontSize=15)
  texto4=Paragraph(f"{df.set_index('concat').loc[i]['Text']}", style=style_texto4)
  style_texto4.leading=16
  texto4.wrapOn(c, 600, 600)
  texto4.drawOn(c, 90, 380)

想象一下我的文字是这样的:

'Hello, my name is John and I am trying to insert some breaklines \n in my pdf so that it displays correctly in my html format'.

这引发了:

syntax error: No content allowed in br tag

【问题讨论】:

  • 欢迎来到 Stack Overflow。请不要大喊大叫。标题会自动突出显示样式。

标签: python html reportlab


【解决方案1】:

换行符 (\n) 将不起作用。您可以通过使用<br /> 标签来实现这一点。

帮助:How to insert a carriage return in a ReportLab paragraph?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多