Sean O
Sean O

Reputation: 177

Is it possible to specify a page template for the first page and another for following pages in reportlab

I am building a fairly simple document in reportlab with platypus. It is basically a header on all the pages and then a table object with line items that will extend onto multiple pages.

What I am trying to figure out is if there is a way to specify one page template for the first page, and a page template for all following pages.

From what I can tell you have to put a call to NextPageTemplate as a flowable in your story, but since one flowable takes up multiple pages I can't put a NextPageTemplate call in there.

I thought there was a way to specify a template onFirstPage and a template onLaterPages when building the document but I can't seem to find that anymore.

Any Ideas?

Upvotes: 0

Views: 875

Answers (1)

Sean O
Sean O

Reputation: 177

Alright I figured it out. Hope this will help someone else in the future.

Where I had seen onFirstPage and onLaterPages was in the build method of the SimpleDocTemplate class. And while for a simpler report it would have worked fine, for mine that method does not work. I am using a frame to specify the margins of my document, there is probably a better way to do this, and the SimpleDocTemplate creates it's own margin Frame, also I might be wrong about that.

Anyways, I subclassed BaseDocTemplate to overide the handle_pageBegin method to tell the build method to switch to the second page template like so:

    def handle_pageBegin(self):
        '''override base method to add a change of page template after the firstpage.
        '''
        self._handle_pageBegin()
        self._handle_nextPageTemplate('Later')

Then I could just add 2 page templates into the document when I create it naming the second one 'Later'.

Seems to work great for now.

Upvotes: 1

Related Questions