Skip to content

Commit 4a5f92e

Browse files
committed
Move pagebreaks to an external plugin
1 parent a7be7db commit 4a5f92e

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'es6-promise/auto';
22

33
import Worker from './worker.js';
44
import './plugin/jspdf-plugin.js';
5+
import './plugin/pagebreaks.js';
56
import './plugin/hyperlinks.js';
67

78
/**

src/plugin/pagebreaks.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Worker from '../worker.js';
2+
3+
var orig = {
4+
toContainer: Worker.prototype.toContainer
5+
};
6+
7+
Worker.prototype.toContainer = function toContainer() {
8+
return orig.toContainer.call(this).then(function toContainer_pagebreak() {
9+
// Enable page-breaks.
10+
var pageBreaks = source.querySelectorAll('.html2pdf__page-break');
11+
var pxPageHeight = this.prop.pageSize.inner.px.height;
12+
Array.prototype.forEach.call(pageBreaks, function pageBreak_loop(el) {
13+
el.style.display = 'block';
14+
var clientRect = el.getBoundingClientRect();
15+
el.style.height = pxPageHeight - (clientRect.top % pxPageHeight) + 'px';
16+
}, this);
17+
});
18+
};

src/worker.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ Worker.prototype.toContainer = function toContainer() {
122122
this.prop.container.appendChild(source);
123123
this.prop.overlay.appendChild(this.prop.container);
124124
document.body.appendChild(this.prop.overlay);
125-
126-
// Enable page-breaks.
127-
var pageBreaks = source.querySelectorAll('.html2pdf__page-break');
128-
var pxPageHeight = this.prop.pageSize.inner.px.height;
129-
Array.prototype.forEach.call(pageBreaks, function pageBreak_loop(el) {
130-
el.style.display = 'block';
131-
var clientRect = el.getBoundingClientRect();
132-
el.style.height = pxPageHeight - (clientRect.top % pxPageHeight) + 'px';
133-
}, this);
134125
});
135126
};
136127

0 commit comments

Comments
 (0)