Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support fitToPageEnabled and scaleFactor #20436

Merged
merged 2 commits into from Oct 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/browser/api/web-contents.js
Expand Up @@ -83,7 +83,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 @@ -209,6 +209,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 @@ -243,7 +249,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