eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
4.05k stars 1.37k forks source link

If you have multiple page-breaks, only the first one has an effect. #112

Open KaiOrange opened 6 years ago

KaiOrange commented 6 years ago

use html2pdf__page-break with multiple times. only the first one has an effect. I found several lines of code in the source code.

  // Enable page-breaks.
  var pageBreaks = source.querySelectorAll('.html2pdf__page-break');
  var pxPageHeight = pageSize.inner.height * pageSize.k / 72 * 96;
  Array.prototype.forEach.call(pageBreaks, function (el) {
    el.style.display = 'block';
    var clientRect = el.getBoundingClientRect();
    el.style.height = pxPageHeight - clientRect.top % pxPageHeight + 'px';
  }, this);

and when clientRect.top is a decimal and pxPageHeight is a decimal, the value of el.style.height is not reliable.so I use the next code Instead.It works..

el.style.height = pxPageHeight - Math.round(clientRect.top) % Math.round(pxPageHeight) + 'px';
Alcoine commented 6 years ago

try to use an empty div with the class="html2pdf__page-break"