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

  • Home
  • SEARCH
  • 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 8158425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:35:41+00:00 2026-06-06T17:35:41+00:00

I am creating PDFs tables with Reportlab platypus. I don´t know, when the page

  • 0

I am creating PDFs tables with Reportlab platypus. I don´t know, when the page is full because of the dynamic content. How can I check out, if I am at the end of the page ?

Is there any method in platypus to check end of page?

I have list of companies and each company has multiple business units with their charges.

   companies = [('company1', 'businessunit1', 500),
                ('company1', 'businessunit2',400),
                ('company2', 'businessunit3',200),
                ('company2', 'businessunit4', 700),
                ('company3', 'businessunit5', 800)
               ]

The above list should generate 3 tables each for one company, but if this list has multiple companies which will generates multiple tables and if any table reaches end of page which will break.

      fields = ['company name', 'business unit name', 'charge']
      for i, comp in enumerate(companies):
          charges = []
          document.append(Paragraph("<b>%s</b>" %comp[i][0], STYLES['COMPANY_NAME']))
          document.append(Spacer(1, 5))
          charges.append(comp[i][0])
          charges.append(comp[i][1])
          charges.append(comp[i][2])
          charges_table = LongTable([fields] + charges, colWidths=(30,150,100))
          charges_table.setStyle(TableStyle([
                          ('BACKGROUND', (0, 0), (-1, 0), colors.gray),
                          ('FONTSIZE', (0, 0), (-1, 0), 6),
                          ('GRID', (0, 0), (-1, -1), 1, colors.gray),
                          ('FONTSIZE', (0, 0), (-1, -1), 7),
                          ('TEXTCOLOR',(0,-1),(-1,-1),'#FF4500'),
                          ])
                          )

          charges_table.hAlign = 'CENTER'
          document.append(charges_table)
  • 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-06T17:35:42+00:00Added an answer on June 6, 2026 at 5:35 pm

    You should provide some sample code so we know what you’re trying to accomplish. Why do you want to know when the page has ended? To draw new content? To print out some diagnostic information?

    Assuming you want to draw something after a page has been rendered, you can use the afterPage() method, which is provided in the BaseDocTemplate class. From ReportLab’s documentation:

    This is called after page processing, and immediately after the afterDrawPage method of the current page template. A derived class could use this to do things which are dependent on information in the page such as the first and last word on the page of a dictionary.

    Basically, it’s called by BaseDocTemplate after a page has been drawn. In the source code, it includes self, as it is part of the BaseDocTemplate class, so you can access its canvas!

    You can override the class in your own script, and then draw onto the canvas directly.

    from reportlab.platypus import BaseDocTemplate
    from reportlab.lib.styles import getSampleStyleSheet
    from reportlab.lib.units import inch
    from reportlab.lib.pagesizes import A4
    from reportlab.platypus import Paragraph
    
    class MyDocTemplate(BaseDocTemplate):
        """Override the BaseDocTemplate class to do custom handle_XXX actions"""
    
        def __init__(self, *args, **kwargs):
            BaseDocTemplate.__init__(self, *args, **kwargs)
    
        def afterPage(self):
            """Called after each page has been processed"""
    
            # saveState keeps a snapshot of the canvas state, so you don't
            # mess up any rendering that platypus will do later.
            self.canv.saveState()
    
            # Reset the origin to (0, 0), remember, we can restore the
            # state of the canvas later, so platypus should be unaffected.
            self.canv._x = 0
            self.canv._y = 0
    
            style = getSampleStyleSheet()
    
            p = Paragraph("This is drawn after the page!", style["Normal"])
    
            # Wraps and draws the paragraph onto the canvas
            # You can change the last 2 parameters (canv, x, y)
            p.wrapOn(self.canv, 2*inch, 2*inch)
            p.drawOn(self.canv, 1*inch, 3*inch)
    
            # Now we restore the canvas back to the way it was.
            self.canv.restoreState()
    

    Now you can use MyDocTemplate the same way you would use BaseDocTemplate in your main logic:

    if __name__ == "__main__":
    
        doc = MyDocTemplate(
            'filename.pdf',
            pagesize=A4,
            rightMargin=.3*inch,
            leftMargin=.3*inch,
            topMargin=.3*inch, 
            bottomMargin=.3*inch
        )
    
        elements = [
            # Put your actual elements/flowables here, however you're generating them.
        ]
    
        doc.addPageTemplates([
            # Add your PageTemplates here if you have any, which you should!
        ])
    
        # Build your doc with your elements and go grab a beer
        doc.build(elements)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my document I am creating 3-4 pdfptables. At design time I don't know
I'm creating PDFs with a library, and I know next to nothing about PDF.
I am creating a web application where users can upload/download/view online pdfs. I want
Does anyone know of a adobe command line tool for creating jpegs from pdfs.
I'm using Reportlab to create PDFs. I'm creating two PDFs which I want to
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
I am creating an ebook for a friend. He has the content in word
I am creating PDFs from xml I am looking for an API which also
Brad Miller @ Cocoa Dev Central wrote a tutorial regarding Creating PDFs from Cocoa.
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,

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.