如何在ReportLab中创建项目符号列表
我该如何在ReportLab中创建一个带项目符号的列表呢?文档写得让人很困惑。我尝试了:
text = ur '''
<para bulletText="•">
item 1
</para>
<para bulletText="•">
item 2
</para>
'''
Story.append(Paragraph(text,TEXT_STYLE))
但是我总是遇到像 list index out of range
这样的错误。看起来我不能在一次调用 Paragraph()
时放入多个 <para></para>
?我还尝试设置 TEXT_STYLE.bulletText="•"
,但这也不管用……
3 个回答
0
这个对我有效。
Story.append(Paragraph('<bullet>•</bullet>Some Text', styles["Bullet"]))
10
最近的ReportLab版本中新增了ListFlowable和ListItem这两个对象(可以查看当前用户指南的第9章)。
10
这里的bulletText参数其实是用来创建Paragraph
对象的,不是<para>
标签哦 :-) 你可以试试这个:
story.append(Paragraph(text, TEXT_STYLE, bulletText='-'))
不过,建议你看看2012年版的ReportLab Documentation
第68页(现在是第74页)上的例子。ReportLab的惯例似乎是使用<bullet>
标签,而且文档也提醒说每个Paragraph
实例只能有一个子弹符号。我们在ReportLab中这样渲染我们的子弹符号:
story.append(Paragraph('<bullet>The rain in spain</bullet>', TEXT_STYLE))