Search code examples
pythonreportlab

ReportLab ListFlowable use custom bullet


I'm using Python 2.7 with reportlab to generate my PDF file. I want to change the bullet style, e.g I want to use dash - or check or cross x instead in the default numbering (1 2 3 4 5 ...)

Here is my code :

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))

I just create my FlowableList and wrap it into a table. But actually the bulletType is bulletType='1' then I have my list with numbers. I tried to replaced this by bulletType='-' but this doesn't work.

Do you have an idea how can I replace all number by another symbol ?


Solution

  • I solved my problem. I found the source code on the reportlab's bitbucket.

    Here is the list of the defaults shapes.

    _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',
                    )
    

    I just have to add the start parameter and set what I want.

    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
    )