【问题标题】:ReportLab ListFlowable use custom bulletReportLab ListFlowable 使用自定义项目符号
【发布时间】:2020-06-17 18:02:33
【问题描述】:

我正在使用 Python 2.7 和 reportlab 来生成我的 PDF 文件。我想更改项目符号样式,例如我想使用破折号- 或检查 或交叉x,而不是默认编号(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 并将其包装到一个表中。但实际上子弹类型是bulletType='1' 然后我有我的数字列表。我试图用bulletType='-' 替换它,但这不起作用。

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

【问题讨论】:

    标签: python reportlab


    【解决方案1】:

    我解决了我的问题。我在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
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 2015-07-10
      相关资源
      最近更新 更多