0
我正在使用ReportLab/Platypus爲基於Django的網站編寫一些PDF生成代碼來生成PDF。Platypus - 在PageTemplate中使用多個框架
我已經將PageTemplate分類了,所以我可以擁有一些一致的頁面修剪,並且包含代碼以生成適合要求的多列布局。我目前已經調試了showBoundary = 1。
但是,我只看到第一幀邊界出現在我呈現兩列布局時。什麼可能出錯?
class ReportPageTemplate(PageTemplate):
def __init__(self, id='basic', columns=1, pagesize=A4, leftMargin=(2*cm), bottomMargin=(2.1*cm), colmargin=(0.5*cm)):
(right, top) = pagesize
right -= leftMargin
top -= bottomMargin
height = top - bottomMargin
width = (right - leftMargin)
# Subtract out blank space between columns
colwidth = (width - ((columns - 1) * colmargin))/columns
frames = []
for col in range(columns):
left = leftMargin + (col * (colwidth + colmargin))
frames.append(Frame(left, bottomMargin, colwidth, height, showBoundary=1))
PageTemplate.__init__(self, id=id, frames=frames, pagesize=pagesize)
def beforeDrawPage(self, canvas, doc):
print self.id
(width, height) = canvas._pagesize
canvas.setLineWidth(0.2 * cm)
canvas.line(0.5*cm, height - (2*cm), width - (0.5*cm), height - (2*cm))
canvas.line(0.5*cm, (2*cm), width - (0.5*cm), (2*cm))