Skip to content

Commit c4d26ff

Browse files
committed
Fix scaling issue introduced in commit 2c0b345
1 parent 1a1a2d0 commit c4d26ff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/html2pdf.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ var html2pdf = (function(html2canvas, jsPDF) {
171171
// Create a one-page canvas to split up the full image.
172172
var pageCanvas = document.createElement('canvas');
173173
var pageCtx = pageCanvas.getContext('2d');
174+
var pageHeight = pageSize.inner.height;
174175
pageCanvas.width = canvas.width;
175176
pageCanvas.height = pxPageHeight;
176177

@@ -179,7 +180,10 @@ var html2pdf = (function(html2canvas, jsPDF) {
179180

180181
for (var page=0; page<nPages; page++) {
181182
// Trim the final page to reduce file size.
182-
if (page === nPages-1) pageCanvas.height = pxFullHeight % pxPageHeight;
183+
if (page === nPages-1) {
184+
pageCanvas.height = pxFullHeight % pxPageHeight;
185+
pageHeight = pageCanvas.height * pageSize.inner.width / pageCanvas.width;
186+
}
183187

184188
// Display the page.
185189
var w = pageCanvas.width;
@@ -191,7 +195,8 @@ var html2pdf = (function(html2canvas, jsPDF) {
191195
// Add the page to the PDF.
192196
if (page) pdf.addPage();
193197
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
194-
pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0]);
198+
pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0],
199+
pageSize.inner.width, pageHeight);
195200

196201
// Add hyperlinks.
197202
if (opt.enableLinks) {

0 commit comments

Comments
 (0)