def analysis_report(request):
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment;filename=ANALYSIS_REPORT.pdf'
buffer = StringIO()
doc = SimpleDocTemplate(buffer)
doc.sample_no = 12345
document = []
doc.build(document, onLaterPages=header_footer)
def header_footer(canvas, doc):
canvas.saveState()
canvas.setFont("Times-Bold", 11)
canvas.setFillColor(gray)
canvas.setStrokeColor('#5B80B2')
canvas.drawCentredString(310, 800, 'HEADER ONE GOES HERE')
canvas.drawString(440, 780, 'Sample No: %s' %doc.sample_no)
canvas.setFont('Times-Roman', 5)
canvas.drawString(565, 4, "Page %d" % doc.page)
上記のコードでは、ページ番号を表示することができますが、私の質問は、Y がページ数で X が現在のページである "Page X of Y" を表示するにはどうすればよいかということです。
私はこのhttp://code.activestate.com/recipes/546511-page-x-of-y-with-reportlab/に従いましたが、ビルドでOnlaterPages引数を使用しているため、canvasmakerを使用して説明しました。
canvasmaker を使用して上記のことを達成するにはどうすればよいですか、または OnLaterPages を使用して解決策はありますか?