Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReportLab: Flowable too large on page 1 in frame 'normal' of template 'First'

I build PDF using ReportLab. My program has a MyDocTemplate(SimpleDocTemplate) class with two methods: beforePage(self) and afterPage(self) which add header and footer (as PNG image) on every page. There is also a MyDocStyle class which describe ParagraphStyle.

Main method looks like this:

TITLE = Paragraph(Title, MyDocStyle.h1)
TO = Paragraph(To, MyDocStyle.h2)
FROM = Paragraph(From, MyDocStyle.h2)
SUBJECT = Paragraph(Subject, MyDocStyle.h2)
LONG_PARAGRAPH = Paragraph(Text, MyDocStyle.h3)
...

Elements = [TITLE, TO, FROM, SUBJECT, LONG_PARAGRAPH, ...]
doc = MyDocTemplete('output.pdf', pagesize=A4, 
                     leftMargin=2*cm, rightMargin=2*cm,
                     topMargin=4*cm, bottomMargin=4*cm)
doc.build(Elements)

Data comes from CSV files and GUI. From time to time (depends on data length) I receive an error:

Flowable <Spacer at 0x2631120 frame=normal>...(1 x 5.66929133858) too large
on page 1 in frame 'normal'(469.88976378 x 603.118110236) of template 'First'

This exception stop my program. For short Paragraphs I set in MyDocStyle class h2.keepWithNext = 1 however it's not perfect solution. ReportLab split correctly long paragraph if end of paragraph does not "coincide" with end of page (text area).

How can I deal with it?

like image 428
kros Avatar asked Oct 09 '11 02:10

kros


1 Answers

This error occurs when ReportLab try to split a Spacer over two pages. It seems that the only way to workaround this issue is wrap your Spacer into a KeepTogether element:

elements.append(KeepTogether(Spacer(width, height)))
like image 115
Salvatore Avanzo Avatar answered Oct 21 '22 03:10

Salvatore Avanzo