mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user