Skip to content

Commit

Permalink
Further multi page size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeCole committed May 24, 2018
1 parent a624012 commit 4d5f3ba
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 23 deletions.
12 changes: 8 additions & 4 deletions dist/html2pdf.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8593,7 +8593,7 @@ Worker.prototype.toPdf = function toPdf() {

// Initialize the PDF.
this.prop.pdf = this.prop.pdf || new jspdf_min(opt.jsPDF);

var currentOffset = 0;
for (var page = 0; page < nPages; page++) {
// Trim the final page to reduce file size.
if (page === nPages - 1) {
Expand All @@ -8602,15 +8602,19 @@ Worker.prototype.toPdf = function toPdf() {
}

// Display the page.
var newW = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[0] : pageCanvas.width;
var newH = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[1] : pageCanvas.height;
var newPageHeight = Math.floor(canvas.width * newRatio);
var w = pageCanvas.width;
var h = pageCanvas.height;
pageCtx.fillStyle = 'white';
pageCtx.fillRect(0, 0, w, h);
pageCtx.drawImage(canvas, 0, page * pxPageHeight, w, h, 0, 0, w, h);
pageCtx.fillRect(0, 0, w, newPageHeight);
pageCtx.drawImage(canvas, 0, currentOffset, w, newPageHeight, 0, 0, w, newPageHeight);
currentOffset += newPageHeight;

// Add the page to the PDF.
if (page) {
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.props.pdf.addPage();
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.prop.pdf.addPage();
}
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0], this.prop.pageSize.inner.width, pageHeight);
Expand Down
2 changes: 1 addition & 1 deletion dist/html2pdf.bundle.min.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/html2pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Worker.prototype.toPdf = function toPdf() {

// Initialize the PDF.
this.prop.pdf = this.prop.pdf || new jsPDF(opt.jsPDF);

var currentOffset = 0;
for (var page = 0; page < nPages; page++) {
// Trim the final page to reduce file size.
if (page === nPages - 1) {
Expand All @@ -321,15 +321,19 @@ Worker.prototype.toPdf = function toPdf() {
}

// Display the page.
var newW = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[0] : pageCanvas.width;
var newH = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[1] : pageCanvas.height;
var newPageHeight = Math.floor(canvas.width * newRatio);
var w = pageCanvas.width;
var h = pageCanvas.height;
pageCtx.fillStyle = 'white';
pageCtx.fillRect(0, 0, w, h);
pageCtx.drawImage(canvas, 0, page * pxPageHeight, w, h, 0, 0, w, h);
pageCtx.fillRect(0, 0, w, newPageHeight);
pageCtx.drawImage(canvas, 0, currentOffset, w, newPageHeight, 0, 0, w, newPageHeight);
currentOffset += newPageHeight;

// Add the page to the PDF.
if (page) {
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.props.pdf.addPage();
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.prop.pdf.addPage();
}
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0], this.prop.pageSize.inner.width, pageHeight);
Expand Down
2 changes: 1 addition & 1 deletion dist/html2pdf.min.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/include/html2pdf.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Worker.prototype.toPdf = function toPdf() {

// Initialize the PDF.
this.prop.pdf = this.prop.pdf || new jsPDF(opt.jsPDF);

var currentOffset = 0;
for (var page = 0; page < nPages; page++) {
// Trim the final page to reduce file size.
if (page === nPages - 1) {
Expand All @@ -316,15 +316,19 @@ Worker.prototype.toPdf = function toPdf() {
}

// Display the page.
var newW = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[0] : pageCanvas.width;
var newH = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[1] : pageCanvas.height;
var newPageHeight = Math.floor(canvas.width * newRatio);
var w = pageCanvas.width;
var h = pageCanvas.height;
pageCtx.fillStyle = 'white';
pageCtx.fillRect(0, 0, w, h);
pageCtx.drawImage(canvas, 0, page * pxPageHeight, w, h, 0, 0, w, h);
pageCtx.fillRect(0, 0, w, newPageHeight);
pageCtx.drawImage(canvas, 0, currentOffset, w, newPageHeight, 0, 0, w, newPageHeight);
currentOffset += newPageHeight;

// Add the page to the PDF.
if (page) {
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.props.pdf.addPage();
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.prop.pdf.addPage();
}
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0], this.prop.pageSize.inner.width, pageHeight);
Expand Down
12 changes: 8 additions & 4 deletions dist/require/html2pdf.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Worker.prototype.toPdf = function toPdf() {

// Initialize the PDF.
this.prop.pdf = this.prop.pdf || new jsPDF(opt.jsPDF);

var currentOffset = 0;
for (var page = 0; page < nPages; page++) {
// Trim the final page to reduce file size.
if (page === nPages - 1) {
Expand All @@ -320,15 +320,19 @@ Worker.prototype.toPdf = function toPdf() {
}

// Display the page.
var newW = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[0] : pageCanvas.width;
var newH = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[1] : pageCanvas.height;
var newPageHeight = Math.floor(canvas.width * newRatio);
var w = pageCanvas.width;
var h = pageCanvas.height;
pageCtx.fillStyle = 'white';
pageCtx.fillRect(0, 0, w, h);
pageCtx.drawImage(canvas, 0, page * pxPageHeight, w, h, 0, 0, w, h);
pageCtx.fillRect(0, 0, w, newPageHeight);
pageCtx.drawImage(canvas, 0, currentOffset, w, newPageHeight, 0, 0, w, newPageHeight);
currentOffset += newPageHeight;

// Add the page to the PDF.
if (page) {
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.props.pdf.addPage();
if (opt.pageSizes && opt.pageSizes[page]) this.prop.pdf.addPage(opt.pageSizes[page].size, opt.pageSizes[page].orientation);else this.prop.pdf.addPage();
}
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0], this.prop.pageSize.inner.width, pageHeight);
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Worker.prototype.toPdf = function toPdf() {

// Initialize the PDF.
this.prop.pdf = this.prop.pdf || new jsPDF(opt.jsPDF);

var currentOffset = 0;
for (var page=0; page<nPages; page++) {
// Trim the final page to reduce file size.
if (page === nPages-1) {
Expand All @@ -201,11 +201,15 @@ Worker.prototype.toPdf = function toPdf() {
}

// Display the page.
var newW = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[0] : pageCanvas.width;
var newH = opt.pageSizes && opt.pageSizes[page] ? opt.pageSizes[page].size[1] : pageCanvas.height;
var newPageHeight = Math.floor(canvas.width * newRatio);
var w = pageCanvas.width;
var h = pageCanvas.height;
pageCtx.fillStyle = 'white';
pageCtx.fillRect(0, 0, w, h);
pageCtx.drawImage(canvas, 0, page*pxPageHeight, w, h, 0, 0, w, h);
pageCtx.fillRect(0, 0, w, newPageHeight);
pageCtx.drawImage(canvas, 0, currentOffset, w, newPageHeight, 0, 0, w, newPageHeight);
currentOffset += newPageHeight;

// Add the page to the PDF.
if (page) {
Expand All @@ -214,7 +218,7 @@ Worker.prototype.toPdf = function toPdf() {
opt.pageSizes[page].size,
opt.pageSizes[page].orientation,
);
else this.props.pdf.addPage();
else this.prop.pdf.addPage();
}
var imgData = pageCanvas.toDataURL('image/' + opt.image.type, opt.image.quality);
this.prop.pdf.addImage(imgData, opt.image.type, opt.margin[1], opt.margin[0],
Expand Down

0 comments on commit 4d5f3ba

Please sign in to comment.