[reportlab-users] reportlab and listflowable

909 views
Skip to first unread message

PB

unread,
Jan 19, 2014, 1:11:53 PM1/19/14
to reportl...@lists2.reportlab.com
Hi,

I'm new here. My case is that i don't want the 5) item. The same problem
is in example: www.reportlab.com/docs/reportlab-userguide.pdf‎ page 86.
Can i fix it? Any idea where i should do that?

BR
pdf.png

Robin Becker

unread,
Jan 20, 2014, 6:48:12 AM1/20/14
to reportlab-users
...
sorry, but I don't understand what you are asking. Please try again if necessary
you can use ascii to indicate what you want eg

items
1) aaaa
2) bbbb
4) dddd

etc etc if you are having trouble describing exactly what you need to ask.
--
Robin Becker
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users

PB

unread,
Jan 20, 2014, 8:15:10 AM1/20/14
to reportlab-users
W dniu 20.01.2014 12:48, Robin Becker pisze:
On 19/01/2014 18:11, PB wrote:
Hi,

I'm new here. My case is that i don't want the 5) item. The same problem
is in example: www.reportlab.com/docs/reportlab-userguide.pdf‎ page 86.
Can i fix it? Any idea where i should do that?

BR
...
sorry, but I don't understand what you are asking. Please try again if necessary you can use ascii to indicate what you want eg

items
1) aaaa
2) bbbb
4) dddd

etc etc if you are having trouble describing exactly what you need to ask.

Thank you for your answer. This is my development of the topic.

The example code:
from reportlab.platypus import ListFlowable, ListItem
from reportlab.lib.styles import getSampleStyleSheet
styles = getSampleStyleSheet()
style = styles["Normal"]

t = ListFlowable(

    [
        Paragraph("Item no.1", style),
        ListItem(Paragraph("Item no. 2", style),bulletColor="green",value=7),
        ListFlowable(
            [

                Paragraph("sublist item 1", style),
                ListItem(Paragraph('sublist item 2', style),bulletColor='red',value='square')
                ],
            bulletType='bullet',
            start='square',
        ),
        Paragraph("Item no.4", style),
        ],
    bulletType='i'
    )


This is output:

i Item no.1
vii Item no. 2
viii ■ sublist item 1
     ■ sublist item 2
ix Item no.4

But the proper output is this in my opinion:

i Item no.1
vii Item no. 2
     ■ sublist item 1
     ■ sublist item 2
viii Item no.4


So the item (ListFlowable with sublist) can not be numbered.

Thanks in advance!

Henning von Bargen

unread,
Jan 20, 2014, 8:36:54 AM1/20/14
to reportl...@lists2.reportlab.com
You wrote:

-------------

|This is output:|
|
i Item no.1
ii Item no. 2
iii ? sublist item 1
? sublist item 2
iv Item no.4

But the proper output is this in my opinion:

i Item no.1
ii Item no. 2
? sublist item 1
? sublist item 2
iii Item no.4

So the item (|ListFlowable with sublist|) can not be numbered.

-------------

I think what ReportLab does is correct.

Probably you mean "should not be numbered". It should be possible to
just use 3 lists.

First list: For Items no.1 + 2
Second list (with extra indent) for the sublist items
Third list: For Item no. 4

For the third list you have to tell it to start with 3 instead of 1 (I
guess that's possible).

Henning

Robert Dodd

unread,
Sep 9, 2014, 7:36:47 PM9/9/14
to reportl...@googlegroups.com, reportl...@lists2.reportlab.com
In HTML a nested list is nested inside the previous list item, like this: 

<ul>
   
<li>List item one</li>
   
<li>List item two with subitems:
       
<ul>
           
<li>Subitem 1</li>
           
<li>Subitem 2</li>
       
</ul>
   
</li>
   
<li>Final list item</li>
</ul>
(Taken from: http://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list)

We can do the same in ReportLab -- by passing the previous paragraph and the nested ListFlowable inside their own array. It groups them together and removes the extra bullet.

t = ListFlowable(
    [
        Paragraph("Item no.1", styleN),
        [
            Paragraph("Item no. 2", styleN),
            ListFlowable(
                [
                    Paragraph("sublist item 1", styleN),
                    ListItem(Paragraph('sublist item 2', styleN), bulletColor='red', value='square')
                ],
                bulletType='bullet',
                start='square',
            )
        ],
        Paragraph("Item no.4", styleN),
    ],
    bulletType='i'
)

I found this totally by accident :) I made a mistake in my code that appended an array instead of joining it.

You should probably check out ReportLab's source to see how this works -- I haven't done that yet so I'm not sure if this is the correct way or whether it might be better to put the array inside a ListItem?

Hope that helps.

Robert Dodd

unread,
Sep 9, 2014, 7:40:15 PM9/9/14
to reportl...@googlegroups.com, reportl...@lists2.reportlab.com
Here's how the above code looks:

And the complete code:

from reportlab.platypus import ListFlowable, ListItem, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.pdfgen.canvas import Canvas
from reportlab.platypus import Paragraph, SimpleDocTemplate

styles = getSampleStyleSheet()
styleN = styles['Normal']
styleH = styles['Heading1']

t = ListFlowable(
    [
        Paragraph("Item no.1", styleN),
        [
            Paragraph("Item no. 2", styleN),
            ListFlowable(
                [
                    Paragraph("sublist item 1", styleN),
                    ListItem(Paragraph('sublist item 2', styleN), bulletColor='red', value='square')
                ],
                bulletType='bullet',
                start='square',
            )
        ],
        Paragraph("Item no.4", styleN),
    ],
    bulletType='i'
)

#add some flowables
story = []
story.append(Paragraph("Look at this list:", styleH))
story.append(t)

doc = SimpleDocTemplate('mydoc.pdf')
doc.build(story)

Prasad Ovhal

unread,
Jul 2, 2019, 7:21:44 AM7/2/19
to reportlab-users


On Wednesday, 10 September 2014 05:10:15 UTC+5:30, Robert Dodd wrote:
Here's how the above code looks:


How can I add numbers instead of bullets? 
Reply all
Reply to author
Forward
0 new messages