Search code examples
pythonlistpdfnestedreportlab

How to set the bullet size in a python reportLab nested list


Good day!

I have defined a nested list in Python reportLab such as this:

t = ListFlowable(
        [
            ListItem(Paragraph("Item 1"), bulletFontSize=9),
            [
                Paragraph("Item 2"),
                ListFlowable(
                    [
                        ListItem(Paragraph("Item 2.1"), bulletFontSize=9),
                        ListItem(Paragraph("Item 2.2"), bulletFontSize=9)
                    ],
                    bulletType='a'
                ),
            ]
        ], bulletType = '1' 
)

, which renders the following nested list:

Nested list rendered

As you see, the numbered bullet "2" has not the correct size. And here comes the problem: if I try to set its size enclosing the Paragraph("Item 2") with a ListItem (so I can set the bulletFontSize property as I do with the others), Python gives me then the following error:

lib\site-packages\reportlab\platypus\flowables.py", line 2048, in wrap
    w,h = self._flowable.wrap(aW-self._leftIndent-self._rightIndent, aH)
AttributeError: 'ListItem' object has no attribute 'wrap'

Any help would be very appreciated. I haven't found any hint in the official documentation (which, BTW, I find a bit obscure) nor StackOverflow.

Thanks a lot!


Solution

  • I think you can add ", bulletFontSize=9" attribute at the end after "bulletType = '1'" for the ListFlowable. It will solve the issue.