diff --git a/package-lock.json b/package-lock.json index 6c10001..d07b9aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2139,9 +2139,9 @@ } }, "node_modules/async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "dependencies": { "lodash": "^4.17.14" @@ -8988,9 +8988,9 @@ "dev": true }, "async": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.3.tgz", - "integrity": "sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==", + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.4.tgz", + "integrity": "sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==", "dev": true, "requires": { "lodash": "^4.17.14" diff --git a/src/plugin/pagebreaks.js b/src/plugin/pagebreaks.js index 5a4dc2b..e4223a3 100644 --- a/src/plugin/pagebreaks.js +++ b/src/plugin/pagebreaks.js @@ -40,7 +40,8 @@ Worker.prototype.toContainer = function toContainer() { return orig.toContainer.call(this).then(function toContainer_pagebreak() { // Setup root element and inner page height. var root = this.prop.container; - var pxPageHeight = this.prop.pageSize.inner.px.height; + // avoid rounding errors by using the exact height in px + var pxPageHeight = this.prop.pageSize.inner.px.heightExact; // Check all requested modes. var modeSrc = [].concat(this.opt.pagebreak.mode); @@ -116,7 +117,7 @@ Worker.prototype.toContainer = function toContainer() { if (rules.before) { var pad = createElement('div', {style: { display: 'block', - height: pxPageHeight - (clientRect.top % pxPageHeight) + 'px' + height: Math.floor(pxPageHeight - (clientRect.top % pxPageHeight)) + 'px' }}); el.parentNode.insertBefore(pad, el); } @@ -125,7 +126,7 @@ Worker.prototype.toContainer = function toContainer() { if (rules.after) { var pad = createElement('div', {style: { display: 'block', - height: pxPageHeight - (clientRect.bottom % pxPageHeight) + 'px' + height: Math.floor(pxPageHeight - (clientRect.bottom % pxPageHeight)) + 'px' }}); el.parentNode.insertBefore(pad, el.nextSibling); } diff --git a/src/utils.js b/src/utils.js index ce0c413..168441f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -73,6 +73,7 @@ export const unitConvert = function unitConvert(obj, k) { }; // Convert units to px using the conversion value 'k' from jsPDF. -export const toPx = function toPx(val, k) { - return Math.floor(val * k / 72 * 96); +export const toPx = function toPx(val, k, floor = true) { + const px = val * k / 72 * 96 + return floor ? Math.floor(px) : px; } diff --git a/src/worker.js b/src/worker.js index 336d7b3..ef34a17 100644 --- a/src/worker.js +++ b/src/worker.js @@ -363,8 +363,10 @@ Worker.prototype.setPageSize = function setPageSize(pageSize) { height: pageSize.height - this.opt.margin[0] - this.opt.margin[2] }; pageSize.inner.px = { - width: toPx(pageSize.inner.width, pageSize.k), - height: toPx(pageSize.inner.height, pageSize.k) + width: toPx(pageSize.inner.width, pageSize.k, true), + height: toPx(pageSize.inner.height, pageSize.k, true), + widthExact:toPx(pageSize.inner.width, pageSize.k, false), + heightExact: toPx(pageSize.inner.height, pageSize.k, false), }; pageSize.inner.ratio = pageSize.inner.height / pageSize.inner.width; }