how to group objects in reportlab, so that they stay together across new pages

后端 未结 3 1663
不知归路
不知归路 2021-02-13 13:37

I\'m generating some pdf files using reportlab. I have a certain section that is repeated. It contains of a header and a table:

            Story.append(Paragrap         


        
3条回答
  •  别跟我提以往
    2021-02-13 14:28

    You can try to put them together in a KeepTogether flowable, like so:

    Story.append(KeepTogether([Paragraph(header_string, styleH), table])
    

    However be aware that, last I checked, the implementation was not perfect and would still split up items too frequently. I know it does a good job of keeping a single flowable together that would otherwise split, like if you were to say:

    Story.append(KeepTogether(Paragraph(header_string, styleH))
    

    then that paragraph would not get split unless it was impossible for it not to be.

    If KeepTogether doesn't work for you, I'd suggest creating a custom Flowable with your paragraph and table inside it and then during layout make sure your custom Flowable subclass does not allow itself to be split up.

提交回复
热议问题