Show different footers on first and consecutive pages with pisa/xhtml2pdf

6k views Asked by At

I'm having some trouble getting a footer to appear as one frame on the first page of a Pisa document, and as another frame on every other page. I have attempted to adapt the lastPage idea from here, but with no luck.

Is it possible to do this? <pdf:nextpage /> doesn't seem to be the right thing here since the document has a long table that may (or may not) flow over multiple pages. <pdf:nextframe /> plus a first-page-only frame looks promising, though I'm not sure how to use this exactly.

Currently I have (snipped for brevity):

<style type="text/css">
  @page {
    margin: 1cm;
    margin-bottom: 2.5cm;
    @frame footer {
      -pdf-frame-content: footerFirst;
      -pdf-frame-border: 1;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
   }
   @frame footer {
      -pdf-frame-content: footerOther;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
}
</style>
<body>
  <table repeat="1">
    <!-- extra long table here -->
  </table>
  <div id="footerContent">This is a footer</div>
  <!-- what goes here to switch frames after the first page? -->
  <div id="footerOther"></div>
</body>

This places the same footer on each page. I need the same space left on each consecutive pages, but with no content in the frame.

1

There are 1 answers

4
Collin Green On

You can define additional layouts by name, then tell xhtml2pdf to switch to them explicitly using the nexttemplate tag. I did exactly this recently to have no header on my first page but to show it on all the subsequent pages.

You should change your @page definition to two different pages, perhaps like this:

<style type="text/css">
  @page {
    margin: 1cm;
    margin-bottom: 2.5cm;
    @frame footer {
      -pdf-frame-content: footerFirst;
      -pdf-frame-border: 1;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
   }
 }

 @page innerpages {
   margin: 1cm;
   margin-bottom: 2.5cm;
   @frame footer {
      -pdf-frame-content: footerOther;
      bottom: 2cm;
      margin-left: 1cm;
      margin-right: 1cm;
      height: 1cm;
   }
 }
</style>

Then, in your html where you want to switch to the different layout, use a tag like this:

<pdf:nexttemplate name="innerpages"/>

The next page (and subsequent pages until you change the template again) will use the innerpages layout with your 'other' footer.