ReportLab ListFlowable 使用自定义项目符号

ReportLab ListFlowable use custom bullet

我使用 Python 2.7 和 reportlab 来生成我的 PDF 文件。我想更改项目符号样式,例如我想在默认编号 (1 2 3 4 5 ...)

这是我的代码:

styles = getSampleStyleSheet()
style = styles["Normal"]

t = ListFlowable(
[
Paragraph("Item no.1", style),
ListItem(Paragraph("Item no. 2", style),bulletColor="green",value=7),
Paragraph("Item no.4", style),
],
bulletType='1'
)

data = [[t, t, t, t]]

table = Table(data, colWidths=(4.83*cm))

table.setStyle(TableStyle([
                       ('BOX', (0,0), (-1,-1), 0.7, colors.black)
                       ]))

table.wrapOn(pdf, width, height)
table.drawOn(pdf, *coord(1.1, 21, cm))

我只是创建了我的 FlowableList 并将其包装到 table 中。但实际上 bulletType 是 bulletType='1' 然后我有我的数字列表。我试图用 bulletType='-' 替换它,但这不起作用。

你知道如何用另一个符号替换所有数字吗?

我解决了我的问题。我在 reportlab 的 bitbucket 上找到了 source code

这是默认形状的列表。

_bulletNames = dict(
                bulletchar=u'\u2022',  # usually a small circle
                circle=u'\u25cf',  # circle as high as the font
                square=u'\u25a0',
                disc=u'\u25cf',
                diamond=u'\u25c6',
                diamondwx=u'\u2756',
                rarrowhead=u'\u27a4',
                sparkle=u'\u2747',
                squarelrs=u'\u274f',
                blackstar=u'\u2605',
                )

我只需要添加启动参数并设置我想要的即可。

t = ListFlowable(
    [
        Paragraph("Item no.1", style),
        ListItem(Paragraph("Item no. 2", style), bulletColor="green", value=7),
        Paragraph("Item no.4", style),
    ],
    bulletType='1',
    start='-'  # You can use default shape or custom char like me here
)