简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM