ReportLab LayoutError:页面太大

时间:2009-12-03 19:20:50

标签: python pdf-generation reportlab platypus

我正在使用ReportLab进行我的第一个程序,我不知道预先在哪里分页,我遇到了麻烦。为了简单起见,我正在使用SimpleDocTemplate。我的flowables看起来像这样:

flowables = [Paragraph("Some title", style=headerParagraphStyle),
             Spacer(0, 10),
             Paragraph("first paragraph", style=bodyParagraphStyle),
             Paragraph("second paragraph", style=bodyParagraphStyle),
             ...
             Paragraph("nth paragraph", style=bodyParagraphStyle),
             PageBreak(),
             Paragraph("Some title", style=headerParagraphStyle),
             Spacer(0, 10),
             Paragraph("first paragraph", style=bodyParagraphStyle),
             Paragraph("second paragraph", style=bodyParagraphStyle),
             ...
             Paragraph("mth paragraph", style=bodyParagraphStyle),
             PageBreak(),
             ...]

当我构建我的PDF时,只要我的nm或多个正文段落适合一页,一切都会顺利,但如果它们结束,我会收到如下错误:

reportlab.platypus.doctemplate.LayoutError: Flowable <Paragraph at 0xb79800 frame=normal>20th paragraph: too large on page 3

似乎无法找到为什么这种情况一直发生在我身上的充分理由。有什么建议?即使我删除PageBreaks(),它也会这样做。所有段落都相对较短,大多不到一个句子/行。

ETA:我发布了为我生成错误的所有代码(删除了次要标识符)。我已将其转换为读取CSV文件,因此我也发布了其内容。运行它时,此代码为我生成的确切错误是:

Traceback (most recent call last):
  File "./spice_dev.py", line 355, in 
    departmentReportDoc.build(eachDepartment.report, onFirstPage=onReportPage, onLaterPages=onReportPage)
  File "/usr/local/lib/python2.6/site-packages/reportlab/platypus/doctemplate.py", line 1010, in build
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
  File "/usr/local/lib/python2.6/site-packages/reportlab/platypus/doctemplate.py", line 777, in build
    self.handle_flowable(flowables)
  File "/usr/local/lib/python2.6/site-packages/reportlab/platypus/doctemplate.py", line 694, in handle_flowable
    raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: Flowable Additional comments and suggestions for improvement: too large on page 3

某些调试工作显示错误是此段落的结果(尽管可能是其他可流动的,具体取决于内容长度)尝试拆分,推迟,然后在调用{{后仍然无法拆分1}}。建议

spice.py:

handle_frameEnd()

spireport2.csv:

College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æsample commentsææi like itæô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205æone with a line break; let's see what happensæææweird charactèrs  áÈ-{ô
College of Health & Public AffæCriminal Justice/Legal Studiesæsample@mail.comæAn InstructoræFOUNDATIONS OF LAW ENFORCEMENTæCJE5021æ0001æ1370æ   7ææææô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205ææææô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205ææææô
College of Health & Public AffæHealth Info Mgmtæexample@example.comæAn InstructoræMEDICAL TERMINOLOGYæHSC3537æ0M01æ1370æ 205ææææô
College of Arts & HumanitiesæEnglishæspam@me.comæAn InstructoræHARLEM, HAITI, AND HAVANAæAML3615æ0001æ1370æ  35ææææô
College of Arts & HumanitiesæEnglishæspam@me.comæAn InstructoræCONT AMERICAN WOMEN S FICTIONæAML3283æ0001æ1370æ  35ææææô
College of Arts & HumanitiesæEnglishæspam@me.comæAn InstructoræPOST-WORLD WAR II FICTIONæLIT4303æ0M01æ1370æ  32ææææô
College of Arts & HumanitiesæEnglishæbill@gates.comæAn InstructoræMAJOR AMERICAN AUTHORSæAML4300æ0001æ1370æ  33ææææô
College of Arts & HumanitiesæEnglishæspam@me.comæAn InstructoræPRACTICAL CRITICISMæENG3010æ0001æ1370æ  36ææææô

2 个答案:

答案 0 :(得分:2)

自己找到了解决方法。基于一些code changes made in rst2pdf,我能够让我的代码可靠地运行。虽然很难看,但解决方案是将我的Paragraphs包裹在为Paragraphs内的学生评论创建KeepTogether的代码部分中。例如,我将一个相关的行改为:

reportDocContent.append(KeepTogether(Paragraph(commentParagraph, style=commentParagraphStyle)))

现在它可以工作了(至少,在尝试了大量的样本数据之后我还没能打破它。)

答案 1 :(得分:1)

看起来这是一个老问题,但我最近经历过同样的错误,来到这里寻找一些建议。我做的修复是使垫片尺寸为旧尺寸的一半。它以前是Spacer(1,0.2 *英寸),我把它换成了Spacer(1,0.1 *英寸)。然后没有更多这样的错误。

仅供参考,我收到的错误消息是

  File "/opt/python2.7/lib/python2.7/site-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 1117, in build
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
  File "/opt/python2.7/lib/python2.7/site-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 880, in build
    self.handle_flowable(flowables)
  File "/opt/python2.7/lib/python2.7/site-packages/reportlab-2.5-py2.7-linux-x86_64.egg/reportlab/platypus/doctemplate.py", line 793, in handle_flowable
    raise LayoutError(ident)
reportlab.platypus.doctemplate.LayoutError: Flowable <Spacer at 0xf01440 frame=normal>...(1 x 14.4) too large on page 10 in frame 'normal'(439.275590551 x 628.28976378) of template 'Later'