简体   繁体   中英

HTML Save as PDF 2 Pages

I have a button to print my html as PDF. Problem is I need it to print in two pages. Different browsers are messing it up and not printing 2nd page right. How do I specific page 2 with my code..

  function printPageArea(areaID){ var printContent = document.getElementById(areaID); var WinPrint = window.open('', '', 'width=830,height=792'); WinPrint.document.write(printContent.innerHTML); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); } 
  <a href="javascript:void(0);" style="position: relative;left: 0;top: 50px;" onClick="printPageArea('printableArea')"><button class="custom" style="width:auto!important;">Download PDF</button></a> <div class="content-wrap-consent" id="printableArea"> <div class="page-one"> Page One </div> <div class="page-two"> Page two </div> </div> 

I think you need to use @media print in css,

Below are some of the links,

Create print styles using CSS3 @media queries

CSS Printing - @media Rule

You can use page-break-before or page-break-after to insert a page break before or after an element, respectively.

@media print {
    .page-two {
        page-break-before: always;
    }
}

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