feat: support fitToPageEnabled and scaleFactor (#20436)

* fix: support fitToPageEnabled and scaleFactor

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

* fix: change default value of scaleFactor
This commit is contained in:
Alecyrus 2019-10-18 08:40:19 +08:00 committed by Cheng Zhao
parent 19223952a8
commit 825e67140e

View file

@ -82,7 +82,7 @@ const defaultPrintingSetting = {
deviceName: 'Save as PDF',
generateDraftData: true,
fitToPageEnabled: false,
scaleFactor: 1,
scaleFactor: 100,
dpiHorizontal: 72,
dpiVertical: 72,
rasterizePDF: false,
@ -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
}
@ -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 {