Skip to content

Commit

Permalink
feat: support fitToPageEnabled and scaleFactor (#20436)
Browse files Browse the repository at this point in the history
* fix: support fitToPageEnabled and scaleFactor

Support fitToPageEnabled and scaleFactor in  `WebContents.printToPDF()`

* fix: change default value of scaleFactor
  • Loading branch information
Alecyrus authored and zcbenz committed Oct 18, 2019
1 parent 1922395 commit 825e671
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/browser/api/web-contents.js
Expand Up @@ -82,7 +82,7 @@ const defaultPrintingSetting = {
deviceName: 'Save as PDF',
generateDraftData: true,
fitToPageEnabled: false,
scaleFactor: 1,
scaleFactor: 100,
dpiHorizontal: 72,
dpiVertical: 72,
rasterizePDF: false,
Expand Down Expand Up @@ -208,6 +208,12 @@ WebContents.prototype.printToPDF = function (options) {
if (options.landscape) {
printingSetting.landscape = options.landscape
}
if (options.fitToPageEnabled) {
printingSetting.fitToPageEnabled = options.fitToPageEnabled
}
if (options.scaleFactor) {
printingSetting.scaleFactor = options.scaleFactor
}
if (options.marginsType) {
printingSetting.marginsType = options.marginsType
}
Expand Down Expand Up @@ -242,7 +248,7 @@ WebContents.prototype.printToPDF = function (options) {
}

// Chromium expects this in a 0-100 range number, not as float
printingSetting.scaleFactor *= 100
printingSetting.scaleFactor = Math.ceil(printingSetting.scaleFactor) % 100
if (features.isPrintingEnabled()) {
return this._printToPDF(printingSetting)
} else {
Expand Down

0 comments on commit 825e671

Please sign in to comment.