【发布时间】:2015-03-13 19:11:14
【问题描述】:
我使用 ReportLab 构建 PDF。我的程序有一个MyDocTemplate(SimpleDocTemplate) 类,它有两种方法:beforePage(self) 和afterPage(self),它们在每个页面上添加页眉和页脚(作为 PNG 图像)。还有一个MyDocStyle 类描述ParagraphStyle。
主方法如下所示:
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)
数据来自 CSV 文件和 GUI。有时(取决于数据长度)我收到一个错误:
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'
这个异常停止了我的程序。对于我在MyDocStyle 类h2.keepWithNext = 1 中设置的简短段落,但这并不是完美的解决方案。如果段落结尾与页面结尾(文本区域)不一致,ReportLab 会正确拆分长段落。
我该如何处理?
【问题讨论】: