00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
00016 from reportlab.lib.styles import getSampleStyleSheet
00017 from reportlab.rl_config import defaultPageSize
00018 from reportlab.lib.units import inch
00019
00020 styles = getSampleStyleSheet()
00021
00022
00023
00024 def myFirstPage(_pdfSettings, canvas, doc):
00025 """
00026 We define the fixed features of the first page of the document with this function.
00027 """
00028 canvas.saveState()
00029 canvas.setFont('Times-Bold',16)
00030 canvas.drawCentredString(_pdfSettings['_pdfCalcs']['_page_width']/2.0, _pdfSettings['_pdfCalcs']['_page_height']-108, _pdfTitle)
00031 canvas.setFont('Times-Roman',9)
00032 canvas.drawString(inch, 0.75 * inch, "First Page / %s" % _pdfSettings['_pdfPageinfo'])
00033 canvas.restoreState()
00034
00035
00036
00037
00038
00039 def myLaterPages(_pdfSettings, canvas, doc):
00040 """
00041 Since we want pages after the first to look different from the first we define an
00042 alternate layout for the fixed features of the other pages. Note that the two functions
00043 above use the pdfgen level canvas operations to paint the annotations for the pages.
00044 """
00045 canvas.saveState()
00046 canvas.setFont('Times-Roman', 9)
00047 canvas.drawString(inch, 0.75 * inch, "Page %d %s" % (doc.page, _pdfSettings['_pdfPageinfo']))
00048 canvas.restoreState()
00049
00050 def go(_pdfSettings):
00051 doc = SimpleDocTemplate("phello.pdf")
00052 print 'Writing PDF to %s' % ( "phello.pdf" )
00053 Story = [Spacer(1,2*inch)]
00054 style = styles["Normal"]
00055 for i in range(100):
00056 bogustext = ("Paragraph number %s. " % i) *20
00057 p = Paragraph(bogustext, style)
00058 Story.append(p)
00059 Story.append(Spacer(1,0.2*inch))
00060 doc.build(Story, onFirstPage=myFirstPage(_pdfSettings),
00061 onLaterPages=myLaterPages(_pdfSettings))