ReportLab - Set the style of the numbers in a numbed list using ListStyle

97 Views Asked by At

I'm using ListStyle to make a numbered list in ReportLab as shown below. But setting the style of the numbers in the list wont work. As an example, changing them to fontSize=6 below does nothing:

from reportlab.lib.styles import ParagraphStyle, ListStyle
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.platypus import ListFlowable, ListItem

filename = filename = g.PATH_TO_SAVE_RL_SAMPLES + "testing_9.pdf"
doc = SimpleDocTemplate(filename, pagesize=pagesizes.portrait(pagesizes.A4), 
        leftMargin = 2.2 * cm, 
        rightMargin = 2.2 * cm,
        topMargin = 1.5 * cm, 
        bottomMargin = 2.5 * cm)

story = []

number_style = ListStyle('number_style', fontName="Helvetica-Bold", fontSize=6)
text_style = ParagraphStyle('number_style', fontName="Helvetica", fontSize=6)

my_list = [
ListItem(Paragraph('List item number one.', text_style), value=1, style=number_style),
ListItem(Paragraph('List item number two.', text_style), value=2, style=number_style),
ListItem(Paragraph('List item number four.', text_style), value=4, style=number_style),
ListItem(Paragraph('List item number eight.', text_style), value=8, style=number_style),
]

story.append(ListFlowable(my_list))

doc.build(story)

Output:

Output

Is there a way to set the style of the numbers in a ListItem?

1

There are 1 best solutions below

0
YesThisIsMe On

I found an answer, I put the following for the ListItem:

ListItem(Paragraph('List item number one.', text_style), value=1, bulletFontSize=5),

Other attributes that can be specified include bulletColor, bulletFontName, bulletIndent, bulletOffsetY. Some information can be found by searching for these in the ReportLab userguide.