html2pdf: <page></page> generates one blank page

Viewed 638

I'm using Html2Pdf for converting some HTML files to PDFs. I'm also required to add page breaks for dividing the parts of my documents. For that I use <page></page> tags.

I have the following HTML snippet:

<!DOCTYPE html>
<html>

<head>
  <style>
    ...
  </style>
</head>

<body>
  <page> page 1 </page>
  <page> page 2 </page>
</body>

</html>

When run the following procedures, I get a PDF with 3 pages, first one being completely blank:

$H2P = new Html2Pdf();
$H2P->writeHTML( $html );
return $H2P->output(__DIR__ .'/statistics.pdf', 'F');

How can I solve this issue? I'm using the latest version installed via composer.

1 Answers

Adding below snippet in style worked for me.

body { margin-top: 0; }

Basically, if you have some margin defined, then you are not at the top of your page when it encounters a named page. So it inserts the named page skipping the existing one.

Related