Reportlab - 如果段落对于一行来说太长,如何引入换行符

发布于 2024-09-25 10:43:55 字数 256 浏览 2 评论 0原文

我有一个要添加到reportlab框架中的文本列表

style = getSampleStyleSheet()['Normal']
style.wordWrap = 'LTR'
style.leading = 12
for legend in legends:
    elements.append(Paragraph(str(legend),style))

如果图例太长,则末尾的文本根本不可见。 在这种情况下如何引入换行符。

I have a list of text to be added to a reportlab frame

style = getSampleStyleSheet()['Normal']
style.wordWrap = 'LTR'
style.leading = 12
for legend in legends:
    elements.append(Paragraph(str(legend),style))

If the legend is too long, the text at the end is not visible at all.
How to introduce line breaks in this situation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天荒地未老 2024-10-02 10:43:55

这可能适用,也可能不适用,但我刚刚了解到,我通常用来在 Python 字符串中引入新行的 \n 会被 ReportLab 的 Paragraph 对象忽略。

邮件列表我了解到,在段落中您可以使用 HTML 的
来引入新行。

这对我来说效果很好。

This may or may not apply but I just learned that \n which I normally use to introduce new lines in Python strings gets ignored by the Paragraph object of ReportLab.

From a mailing list I learned that inside Paragraph you can use HTML's <br/> to introduce the new line instead.

That works well for me.

沉溺在你眼里的海 2024-10-02 10:43:55

正如 PolyGeo 所说,您可以使用
将新行添加到段落。

将新行转换为
标签

replace('\n','<br />\n')

更新代码

 for legend in legends:
        content = str(legend).replace('\n','<br />\n')
        elements.append(Paragraph(content, style))

As PolyGeo says, you can use <br /> to add new lines to a Paragraph.

Convert new lines to <br /> tags

replace('\n','<br />\n')

Updated code

 for legend in legends:
        content = str(legend).replace('\n','<br />\n')
        elements.append(Paragraph(content, style))
救星 2024-10-02 10:43:55
style.wordWrap = 'LTR'

抱歉,如果我将其误解为字母,但段落本身是“自动换行”的,与文档页面大小也有关。

亚洲语言的用户指南值为“CJK”,可能您的设置是根据其他内容(例如亚洲语言分词)执行文本搜索终点线。将其设置为 None 应该可以完成此操作。

style.wordWrap = 'LTR'

Sorry if I misunderstood this as letter, but Paragraph itself is "word wrapped", in relation to document pagesize also.

There's userguide value of 'CJK' for Asian language, possibly your setting do the text to search for finishing line according to something else, like Asian language word splitting. Set it to None should do the thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文