Merge pull request #5812 from vasumahesh1/feature-pdf
webContents: custom pageSize for printToPDF
This commit is contained in:
commit
0565c42add
2 changed files with 25 additions and 5 deletions
|
@ -196,11 +196,31 @@ let wrapWebContents = function (webContents) {
|
|||
if (options.printBackground) {
|
||||
printingSetting.shouldPrintBackgrounds = options.printBackground
|
||||
}
|
||||
if (options.pageSize && PDFPageSize[options.pageSize]) {
|
||||
printingSetting.mediaSize = PDFPageSize[options.pageSize]
|
||||
} else {
|
||||
printingSetting.mediaSize = PDFPageSize['A4']
|
||||
|
||||
if (options.pageSize) {
|
||||
let height = 0
|
||||
let width = 0
|
||||
if (typeof options.pageSize === 'object') {
|
||||
// Dimensions in Microns
|
||||
// 1 meter = 10^6 microns
|
||||
height = options.pageSize.height ? options.pageSize.height : 0
|
||||
width = options.pageSize.width ? options.pageSize.width : 0
|
||||
}
|
||||
|
||||
if (height > 0 && width > 0) {
|
||||
printingSetting.mediaSize = {
|
||||
height_microns: height,
|
||||
name: 'CUSTOM',
|
||||
width_microns: width,
|
||||
custom_display_name: 'Custom'
|
||||
}
|
||||
} else if (PDFPageSize[options.pageSize]) {
|
||||
printingSetting.mediaSize = PDFPageSize[options.pageSize]
|
||||
} else {
|
||||
printingSetting.mediaSize = PDFPageSize['A4']
|
||||
}
|
||||
}
|
||||
|
||||
return this._printToPDF(printingSetting, callback)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue