Frank
Frank

Reputation: 67

How to paginate the PDF while using mpdf to generate PDF file from HTML

I'm using MPDF to generate PDF from HTML. It works perfectly fine while I made the HTML string and pass it to the PDF generator. But I find out it's not enough. How could I change the current page to the next page. I mean in HTML string. For example, if you're making some PDF for the delivery forms on your website. You want to make every form start with a fresh new page. But the MPDF will auto paginate the HTML content which might cannot fit your need. How can I deal with this part? I'm getting confused. I try to read the source code,but the code is too much. And there's not enough comment inside. I hope there's some one who familiar with the MPDF lib. The version of MPDF which I'm using is v5.4 by the way.

Upvotes: 0

Views: 1608

Answers (2)

Niranjan N Raju
Niranjan N Raju

Reputation: 11987

Even i had the problem of breaking the page in mpdf. For that you should use addPage() of mpdf or <pagebreak />

$mpdf->AddPage();

or

<pagebreak />

using either of the above, you can force page breaks in mpdf, check this for more reference

Upvotes: 1

camelCase
camelCase

Reputation: 5598

Unclear exactly what you need, but this might get you going.

If you have a multiple forms and you want those forms to be on their own pages, you have a couple possible solutions:

  1. You could iterate over the forms and use $mpdf->AddPage(); at the end of each form

  2. If you have an entire string and the forms are all together, you could use the html tag <pagebreak /> to signal a break where you'd like.

Reference the docs for further information, if needed. Hope it helps.

Upvotes: 0

Related Questions