46

Is it possible to add a new page in DOMpdf? Similar to mPDF AddPage(); functionaly. I can't seem to find anything in the documentation, is there any work around to this?

I can't seem to find anything in the documentation.

Kitalpha
  • 507
  • 1
  • 5
  • 10

5 Answers5

79

dompdf takes care of paging automagically. If you want to force a page break you can do so by styling an element with page-break-before: always; or page-break-after: always;.

BrianS
  • 13,284
  • 15
  • 62
  • 125
63

Just an example for BrianS's answer:

CSS

.page_break { page-break-before: always; }

HTML

<div class="page_break"></div>
Community
  • 1
  • 1
cottton
  • 1,522
  • 14
  • 29
  • 2
    If you having issue where an extra blank page is added at the end, it is actually caused by the newline that comes after the closing tag. Putting both the

    and

    on the same line as the last

    – FaizFizy Jan 23 '21 at 06:50
13

All answers presented here will make DomPDF to add a blank page to the end of the PDF file. Here is how to fix that:

CSS:

div.page_break + div.page_break{
    page-break-before: always;
}

HTML:

<div class="page_break"></div>
Andresa Martins
  • 280
  • 2
  • 9
  • The problem is caused by the newline that comes after the closing tag. Putting both the

    and

    on the same line as the last

    – FaizFizy Jan 23 '21 at 06:46
10

may be will be helpfull for auto generation some pages

<div class="wrapper-page">
    ... page content ...    
</div>

css

.wrapper-page {
    page-break-after: always;
}

.wrapper-page:last-child {
    page-break-after: avoid;
}

https://github.com/dompdf/dompdf/wiki/CSSCompatibility

andrei040191
  • 408
  • 4
  • 7
4

If the other answer doesn't work for you (as it is for me), you can add a CSS class :

.page { width: 100%; height: 100%; }

and encapsulate every "page" in an element with this class. Not the prettiest way, but it does the job.

Didier Sampaolo
  • 2,566
  • 4
  • 24
  • 34