phpmagentodompdf

How to get multiple pages with Dompdf


I'm using dompdf in Magento 2 to download the multiple PDFs for an invoice but getting only one page. Can someone please help me?

$domPdf = new Dompdf();
$domPdf->loadHtml($html);
$domPdf->setPaper('A4', 'portrait');
$domPdf->render();

This is the code to convert to PDF.

Thanks in advance


Solution

  • Unfortunately it requires additional work to realize multi page. You have to custom style your HTML string used for the loadHtml function to support multi page. For example:

    <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>Title</title>
      </head>
      <body>
        <div class="page">
          this is page 1
        </div>
        <div class="page">
          this is page 2
        </div>
        <div class="page">
          this is page 3
        </div>
      </body>
    
      <style>
        .page {
           page-break-after: always;
        }
        .page:last-child {
           page-break-after: unset;
        }
      </style>
    </html>