Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8338383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:34:36+00:00 2026-06-09T04:34:36+00:00

I am trying to generate a PDF with reportlab that has headers and footers

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:34:39+00:00Added an answer on June 9, 2026 at 4:34 am

    Try:

    doc.append(PageBreak())
    

    for closing a page and opening the next one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have small web app that generate PDF files as a report. I'm trying
G'day guys, trying to build a small invoicing system (that can generate PDF's using
We're trying to create a .NET aspx page that will have a PDF within
I am trying to generate a PDF from a web page (or series of
I am trying to find a library/tool that would allow me to generate PDF
I am trying to generate pdf using automated bash shell script, that script after
I am trying to find a SDK that can generate PDF from OpenXml. I
I'm trying to generate a PDF using WKHTMLTOPDF that requires me to first log
I'm trying to develop a small script that generate a complete new pdf, mainly
I am trying to generate on-the-fly PDF reports from Java objects. I have not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.