Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/plugin/pagebreaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,22 @@ Worker.prototype.toContainer = function toContainer() {
var clientRect = el.getBoundingClientRect();
el.style.height = pxPageHeight - (clientRect.top % pxPageHeight) + 'px';
}, this);

// Shim some padding before elements that would otherwise intersect a page break
pageBreaks = this.prop.container.querySelectorAll('.html2pdf__avoid-page-break');
Array.prototype.forEach.call(pageBreaks, function pageBreak_loop(el) {
var clientRect = el.getBoundingClientRect();
var startPage = Math.floor(clientRect.top / pxPageHeight);
var endPage = Math.floor(clientRect.bottom / pxPageHeight);
if (endPage > startPage && Math.abs(endPage - startPage) === 1) {
// the element is straddling a single page break.
// insert a padding div to push the element to the next page.
var currentDocHeight = (startPage + 1) * pxPageHeight;
var pad = document.createElement('div');
pad.style.display = 'block';
pad.style.height = currentDocHeight - clientRect.top % currentDocHeight + 'px';
el.parentNode.insertBefore(pad, el);
}
}, this);
});
};
};