How to create a bulleted list in ReportLab

自作多情 提交于 2019-12-18 13:33:09

问题


How can I create a bulleted list in ReportLab? The documentation is frustratingly vague. I am trying:

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

But I keep getting errors like list index out of range. It seems that I can't put more than one <para></para> in a single call to Paragraph()? I also tried setting TEXT_STYLE.bulletText="&bull;" but that doesn't work either...


回答1:


The bulletText argument is actually a constructor to the Paragraph object, not the <para> tag :-) Try this:

story.append(Paragraph(text, TEXT_STYLE, bulletText='-'))

Have a look at the examples on page 68 (page 74 now, in 2012) of the ReportLab Documentation, though. The convention in ReportLab seems to be to use the <bullet> tag, and the docs do warn that you can have only one per Paragraph instance. We render our bullets in ReportLab like so:

story.append(Paragraph('<bullet>The rain in spain</bullet>', TEXT_STYLE))



回答2:


The very recent versions of ReportLab have ListFlowable and ListItem objects (check Chapter 9 of the current user guide).



来源:https://stackoverflow.com/questions/748881/how-to-create-a-bulleted-list-in-reportlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!