I am trying to generate a PDF with reportlab that has headers and footers starting on the second page.
I read the threads: Add page break to Reportlab Canvas object and Non-numbered pages in ReportLab
Using functions from these threads I can sucessfully close the title page with canvas.showPage() and can sucessfully start headers/ footers using doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages).
However, when I close the canvas.showPage(), my headers and footers begin on page THREE, not page TWO.
CODE:
def firstPage(canvas,doc):
canvas.setFont('Times-Bold',40)
canvas.drawString(inch, pageHeight-(3*inch), 'docTitle1') #w,h,txt
canvas.drawString(2*inch, pageHeight-(4*inch), 'docTitle2')
canvas.showPage() #force pagebreak
def laterPages(canvas, doc):
canvas.saveState()
canvas.setFont('Times-Roman',9)
canvas.setStrokeColorRGB(2,2,2) #169,169,169)
canvas.drawString(0.5*inch, pageHeight-(0.75*inch), 'header1')
canvas.drawString(pageWidth-inch, pageHeight-(0.75*inch), 'header2')
canvas.drawCentredString(pageWidth/2, 0.65*inch, 'footer1')
canvas.drawCentredString(pageWidth/2, 0.5*inch, 'footer2')
canvas.drawString(pageWidth-inch, 0.6*inch, `doc.page`) #page number
canvas.restoreState()
def build_pdf(elements, doc_name):
doc = SimpleDocTemplate(doc_name)
doc.build(elements, onFirstPage=firstPage, onLaterPages=laterPages)
elements = [title, table1, spacer]
doc_name = 'myPDF.pdf'
build_pdf(elements, doc_name)
How can i stop drawing on the first page and still have onLaterPages begin on page TWO?