如何在ReportLab中创建项目符号列表

use*_*478 6 python pdf reportlab

如何在ReportLab中创建项目符号列表?文档令人沮丧地含糊不清.我在尝试:

text = ur '''
<para bulletText="&bull;">
item 1
</para>
<para bulletText="&bull;">
item 2
</para>
'''
Story.append(Paragraph(text,TEXT_STYLE))
Run Code Online (Sandbox Code Playgroud)

但我不断收到错误list index out of range.看来我不能<para></para>在一次通话中加一个以上Paragraph()?我也试过设置,TEXT_STYLE.bulletText="&bull;"但这也不起作用......

Jar*_*die 7

bulletText参数实际上是Paragraph对象的构造函数,而不是<para>标记:-)试试这个:

story.append(Paragraph(text, TEXT_STYLE, bulletText='-'))
Run Code Online (Sandbox Code Playgroud)

但是,请查看ReportLab文档的第68页(现在,2012年第74页)中的示例.ReportLab中的约定似乎是使用<bullet>标记,文档会警告您每个Paragraph实例只能有一个.我们在ReportLab中渲染我们的项目符号如下:

story.append(Paragraph('<bullet>The rain in spain</bullet>', TEXT_STYLE))
Run Code Online (Sandbox Code Playgroud)


小智 6

ReportLab的最新版本具有ListFlowable和ListItem对象(请参阅当前用户指南的第9章)。