11

I'm using dompdf to generate a PDF. I've grabbed the code from the dompdf website to add a Header to the pdf and it's working, but I would like to put the header on every page except for the first. Any suggestions?

Fabien Ménager
  • 140,109
  • 3
  • 41
  • 60
Kenny Wyland
  • 20,844
  • 26
  • 117
  • 229

3 Answers3

17

You can do this by inserting the header and footer elements after the elements that appear in the first page.

For example :

<style>
  .flyleaf {
    page-break-after: always;
  }

  .header, .footer {
    position: fixed;
  }

  .header {
    top: 0;
  }

  .footer {
    bottom: 0;
  }
</style>

<div class="flyleaf">
  Some big title
</div>

<div class="header">
  my header
</div>

<div class="footer">
  my footer blah, blah
</div>

<p>The content</p>

Edit: added the style tag

Fabien Ménager
  • 140,109
  • 3
  • 41
  • 60
  • 3
    Yeah, that's what I ended up doing. Just making the header and footer part of the page. I found it was far more difficult to hard-code PDF canvas calls in a php script than to just include more html for the header and footer. – Kenny Wyland Aug 27 '11 at 17:56
  • 2
    Great, I forgot to mention that the header and footer elements were positionned with the CSS position:fixed; and with top:0px and bottom:0px; in my example but you might already know it. – Fabien Ménager Aug 27 '11 at 18:52
5

Because when you set header, header will appear of every page of the document, you can use div element to hide header from first page. Div with white background color and z-index greater then header and you will put that div on the top of the page and set position exactly over first page header.

<div style="background-color: white; z-index: 2;"></div>

I have tested this and its worked. I wish this will help.

0

Same issue, explained by a DOMPDF Project Member

https://github.com/dompdf/dompdf/issues/347

Worked for me, my first page is a cover (no header no footer)

BrianS
  • 13,284
  • 15
  • 62
  • 125
Memonic
  • 345
  • 5
  • 14