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

1

6

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.

Elvyn answered 20/1, 2012 at 20:56 Comment(0)
L
7

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.

Lettie answered 19/3, 2012 at 21:29 Comment(4)
I've the opposite problem: change footer on last page. Is there a similar solution? ThanksCorinthian
@Don: it is the same solution - make a different template for your last page and switch to it before the last page using the <pdf:nexttemplate/> tag, just like above.Lettie
but how can I tell if I'm on the page before the last one? (I cannot tell how many rows fit one page, so I can't predict how many pages the document will be...)Corinthian
@Don: you make the last page its own template, and switch to that when you're ready. If you are trying to put dynamic content onto your last page which may or may not ALWAYS have the content, you might need to get more fancy. I have a current product that has a special last page after rows and rows of output - instead of trying to get the last rows onto the special page we just run the last page on its own -- no idea if that will help your situation or not.Lettie

© 2022 - 2024 — McMap. All rights reserved.