Skip to content

Commit

Permalink
Fix scaling issue introduced in commit 2c0b345
Browse files Browse the repository at this point in the history
  • Loading branch information
eKoopmans committed May 25, 2017
1 parent 1a1a2d0 commit c4d26ff
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/html2pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ var html2pdf = (function(html2canvas, jsPDF) {
// Create a one-page canvas to split up the full image.
var pageCanvas = document.createElement('canvas');
var pageCtx = pageCanvas.getContext('2d');
var pageHeight = pageSize.inner.height;
pageCanvas.width = canvas.width;
pageCanvas.height = pxPageHeight;

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

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

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

// Add hyperlinks.
if (opt.enableLinks) {
Expand Down

0 comments on commit c4d26ff

Please sign in to comment.