Skip to content

Commit 5edda1d

Browse files
feat: add PR eKoopmans#260 and eKoopmans#261
1 parent 92f9315 commit 5edda1d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ html2pdf().set({
192192

193193
// Enable all 'modes', with no explicit elements.
194194
html2pdf().set({
195-
pagebreak: { mode: ['avoid-all', 'css', 'legacy'] }
195+
pagebreak: { mode: ['avoid-all', 'css', 'legacy'], elementType: 'tr', className: 'page_break' } // merge of https://github.com/eKoopmans/html2pdf.js/pull/261
196196
});
197197

198198
// No modes, only explicit elements.

src/plugin/pagebreaks.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ Worker.template.opt.pagebreak = {
3333
mode: ['css', 'legacy'],
3434
before: [],
3535
after: [],
36-
avoid: []
36+
// https://github.com/eKoopmans/html2pdf.js/pull/260
37+
avoid: [],
38+
elementType: 'div', //default element to create
39+
className: '' //by default no class
3740
};
3841

3942
Worker.prototype.toContainer = function toContainer() {
@@ -114,11 +117,15 @@ Worker.prototype.toContainer = function toContainer() {
114117
}
115118

116119
// Before: Create a padding div to push the element to the next page.
120+
// https://github.com/eKoopmans/html2pdf.js/pull/260/files (slightly adjusted)
121+
// allow for creating any type of element e.g. 'tr'
122+
// this is useful for tables and other cases where a 'div' will ruin the styling and cannot be handled by simply using the div selector as thats too broad.
117123
if (rules.before) {
118-
var pad = createElement('div', {style: {
119-
display: 'block',
120-
height: pxPageHeight - (clientRect.top % pxPageHeight) + 'px'
121-
}});
124+
var pad = createElement(self.opt.pagebreak.elementType || "div", {
125+
style: {
126+
display: 'block',
127+
height: pxPageHeight - (clientRect.top % pxPageHeight) + 'px'
128+
}, className: self.opt.pagebreak.className}); //allow control of styling of added sections
122129
el.parentNode.insertBefore(pad, el);
123130
}
124131

0 commit comments

Comments
 (0)