简体   繁体   中英

How to convert HTML page in multi page PDF in JavaScript

I have following html page

<html>
  <body>
    <img src="..."/>
    <img src="..."/>
    <img src="..."/>
  </body>
</html>

I want to make the pdf of this page but every image should be on new page.

You could loop over the images using Javascript. Then for each image store is as an data url with dom-to-image here

and print each dataUrl with pdfmake here

Use css property page-break-before: always;

See example HTML below:

<html>
  <head>
   <style>
     .page-heading { page-break-before: always; }
   </style>
  </head>
  <body>
    <img src="..."/>    
    <div class="page-heading">
       <img src="..."/>
    </div>
    <div class="page-heading">
       <img src="..."/>
    </div>
  </body>
</html>

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