简体   繁体   中英

Python Reportlab RML. How to split table row on two pages

I'm wondering if there is some functionality to split table row on two and more pages. Cause some information in row can be too long for one page, and if one row longer then page size then it's cause an exception.

ReportLab does not text wrapping out of the box, so I am assuming you are either using a para in the table cells, or you are breaking your lines manually with simpleSplit.

If you text is one line string then you can use

from reportlab.pdfbase.pdfmetrics import stringWidth
textWidth = stringWidth(text, fontName, fontSize)

If your text was multi-lines, assuming you are working in a rectangular area with defined width, then do

from reportlab.lib.utils import simpleSplit
lines = simpleSplit(text, fontName, fontSize, maxWidth)

lines is a list of all the lines of your paragraph, if you know the line spacing value then the height of the paragraph can be calculated as lineSpacing*len(lines)

If this proved to be longer than your page then using whatever template you are in (preppy, django, ninja, etc) finds a good breaking point for your text and ends the current row and starts a new one.

I hope this helps

Meitham

ps you could always send your questions to the reportlab mailing list and they usually very quick in answering these questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM