猿问

带有嵌套项目符号点的 ReportLab 编号

我在 ReportLab 上苦苦挣扎,我想用它来生成 PDF 作为来自视图的 Django 的请求。

我试着得到一个编号列表,中间有要点

  1. 文本 1 blabla

    • 子弹-blabla

    • 子弹-blabla

  2. 文本 2 blabla

但我收到的是:

  1. 文本 1 blabla


    • 子弹-blabla

    • 子弹-blabla

  2. 文本 2 blabla

我怎样才能抑制“2”。在项目符号前面或者我如何跳过该区域?

这是我的代码

lf = ListFlowable([ ListItem(Paragraph(text1, styles["Normal"])), 
        ListFlowable([ListItem(Paragraph(text1a, styles["Normal"])), 
                    ListItem(Paragraph(text1b, styles["Normal"])),
                    ListItem(Paragraph(text1c, styles["Normal"])),
                    ListItem(Paragraph(text1d, styles["Normal"])),
                 ], bulletType='bullet', bulletFontSize= 5, bulletOffsetY= -2, leftIndent=10, start='circle'),
        ListItem(Paragraph(text2, styles["Normal"]))
        ], bulletType='1')


慕神8447489
浏览 205回答 3
3回答

BIG阳

这是搜索如何在 ReportLab 中制作嵌套列表的人们的最佳结果,您可以将ListFlowablealist作为其项目之一。如果其中list包含 aParagraph和 another ,它将在同一个项目符号点内ListFlowable呈现嵌套ListFlowable在 the 之后的Paragraph权利。t = ListFlowable(    [        Paragraph("Item no. 1", style),        [            Paragraph("Item no. 2", style),            ListFlowable(                [                    Paragraph("sublist item 1", style),                    ListItem(Paragraph('sublist item 2', style), bulletColor='red')                ],                bulletType='bullet',                bulletFontSize=5,                start='square',            )        ],        Paragraph("Item no. 3", style),    ],    bulletType='1',    bulletFormat='%s.',    bulletFontSize=8,)不要费心隐藏多余的项目符号,或告诉 ReportLab 不要渲染它然后必须仔细管理value后续的ListItem项目符号。<ul>它与 HTML 中的s 和s完全一样<ol>。上面的代码呈现如下:

潇湘沐

您可以通过将嵌套列表插入 ListItem 并将值参数设置为 0 来关闭一个列表项的编号:ListFlowable([ Paragraph(...), ListItem(ListFlowable(...nested list...), value= 0) ListItem(Paragraph(...), value=2) # 让列表继续下去 ])

汪汪一只猫

所以我现在想出解决这个问题的方法是将它再次嵌套在另一个 ListFlowable 中,并将 leftIndent 设置为“0”,将 bulletColor 设置为“white”。lf = ListFlowable([&nbsp;&nbsp; &nbsp; ListFlowable([&nbsp; &nbsp; ListItem(Paragraph(text1, styles["Normal"]), spaceAfter=12),&nbsp;&nbsp; &nbsp; ListFlowable([ListItem(Paragraph(text1a, styles["Normal"])),&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListItem(Paragraph(text1b, styles["Normal"])),t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;], bulletType='bullet', bulletFontSize= 5, bulletOffsetY= -2, leftIndent=10, start='circle')], bulletColor='white', leftIndent=0),&nbsp; &nbsp; ListItem(Paragraph(text2, styles["Normal"]), spaceBefore=12),&nbsp; &nbsp; ], bulletType='1', bulletFontSize= 10)
随时随地看视频慕课网APP

相关分类

Python
我要回答