reportlab LayoutError: Flowable Spacer too large

reportlab LayoutError: Flowable Spacer too large

我正在使用 reportlab 3.2.0。

SPACER = Spacer(0, 10)
buff = BytesIO()
doc = SimpleDocTemplate(buff, rightMargin=0.2 * inch,
                        leftMargin=0.2 * inch,\
                        topMargin=100, bottomMargin=68)
elements = []
# here add elements
elements.append(SPACER)
# here add more elements
doc.build(elements)

每当 space 接近页面底部时,我都会收到此错误:

File "/venv/lib/python2.7/site-packages/reportlab/platypus/doctemplate.py", line 1171, in build
    BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
  File "/venv/lib/python2.7/site-packages/reportlab/platypus/doctemplate.py", line 927, in build
    self.handle_flowable(flowables)
  File "/venv/lib/python2.7/site-packages/reportlab/platypus/doctemplate.py", line 829, in handle_flowable
    raise LayoutError(ident)
LayoutError: Flowable <Spacer at 0x4c87d40 frame=normal>...(0 x 10) too large on page 2 in frame 'normal'(554.475590551 x 661.88976378) of template 'Later'

有没有办法防止它抛出异常(即忽略 space 元素)?

这是 Spacer 的快速实现,它用完了您分配给它的高度中的较小者或当前页面剩余的 space。

class ConditionalSpacer(Spacer):

    def wrap(self, availWidth, availHeight):
        height = min(self.height, availHeight-1e-8)
        return (availWidth, height)

您可以像Spacer一样使用它。