Add: custom pageSize for printToPDF
This commit is contained in:
parent
f5839c3a5b
commit
fc6628d159
2 changed files with 25 additions and 5 deletions
|
@ -655,7 +655,7 @@ size.
|
||||||
* `marginsType` Integer - Specifies the type of margins to use. Uses 0 for
|
* `marginsType` Integer - Specifies the type of margins to use. Uses 0 for
|
||||||
default margin, 1 for no margin, and 2 for minimum margin.
|
default margin, 1 for no margin, and 2 for minimum margin.
|
||||||
* `pageSize` String - Specify page size of the generated PDF. Can be `A3`,
|
* `pageSize` String - Specify page size of the generated PDF. Can be `A3`,
|
||||||
`A4`, `A5`, `Legal`, `Letter` and `Tabloid`.
|
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height` & `width` in Microns.
|
||||||
* `printBackground` Boolean - Whether to print CSS backgrounds.
|
* `printBackground` Boolean - Whether to print CSS backgrounds.
|
||||||
* `printSelectionOnly` Boolean - Whether to print selection only.
|
* `printSelectionOnly` Boolean - Whether to print selection only.
|
||||||
* `landscape` Boolean - `true` for landscape, `false` for portrait.
|
* `landscape` Boolean - `true` for landscape, `false` for portrait.
|
||||||
|
|
|
@ -197,11 +197,31 @@ let wrapWebContents = function (webContents) {
|
||||||
if (options.printBackground) {
|
if (options.printBackground) {
|
||||||
printingSetting.shouldPrintBackgrounds = options.printBackground
|
printingSetting.shouldPrintBackgrounds = options.printBackground
|
||||||
}
|
}
|
||||||
if (options.pageSize && PDFPageSize[options.pageSize]) {
|
|
||||||
printingSetting.mediaSize = PDFPageSize[options.pageSize]
|
if (options.pageSize) {
|
||||||
} else {
|
let height = 0
|
||||||
printingSetting.mediaSize = PDFPageSize['A4']
|
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)
|
return this._printToPDF(printingSetting, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue