def get(self, request, *args, **kwargs):
with tempfile.NamedTemporaryFile(suffix=".pdf") as f:
doc = BaseDocTemplate(
f.name, pagesize=A4,
leftMargin=0, rightMargin=0, topMargin=0, bottomMargin=0
)
doc.addPageTemplates([
PageTemplate(
id='All',
frames=[
Frame(
0, 0, doc.width / 2, doc.height,
leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0,
id='left'
),
Frame(
doc.width / 2, 0, doc.width / 2, doc.height,
leftPadding=0, rightPadding=0, topPadding=0, bottomPadding=0,
id='right'
)
],
pagesize=A4
)
])
doc.build(self.get_story(doc))
f.seek(0)
r = HttpResponse(content_type='application/pdf')
r.write(f.read())
return r
评论列表
文章目录