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:
parent
19223952a8
commit
825e67140e
1 changed files with 8 additions and 2 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue