feat: add more options to printToPDF (#21906)

This commit is contained in:
Shelley Vohr 2020-01-28 20:47:24 +00:00 committed by GitHub
parent 1b4eb0b679
commit 548b290ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 171 additions and 53 deletions

View file

@ -1273,9 +1273,11 @@ Returns [`PrinterInfo[]`](structures/printer-info.md)
* `pagesPerSheet` Number (optional) - The number of pages to print per page sheet.
* `collate` Boolean (optional) - Whether the web page should be collated.
* `copies` Number (optional) - The number of copies of the web page to print.
* `pageRanges` Record<string, number> (optional) - The page range to print. Should have two keys: `from` and `to`.
* `pageRanges` Record<string, number> (optional) - The page range to print.
* `from` Number - the start page.
* `to` Number - the end page.
* `duplexMode` String (optional) - Set the duplex mode of the printed web page. Can be `simplex`, `shortEdge`, or `longEdge`.
* `dpi` Object (optional)
* `dpi` Record<string, number> (optional)
* `horizontal` Number (optional) - The horizontal dpi.
* `vertical` Number (optional) - The vertical dpi.
* `header` String (optional) - String to be printed as page header.
@ -1301,14 +1303,21 @@ win.webContents.print(options, (success, errorType) => {
#### `contents.printToPDF(options)`
* `options` Object
* `headerFooter` Record<string, string> (optional) - the header and footer for the PDF.
* `title` String - The title for the PDF header.
* `url` String - the url for the PDF footer.
* `landscape` Boolean (optional) - `true` for landscape, `false` for portrait.
* `marginsType` Integer (optional) - Specifies the type of margins to use. Uses 0 for
default margin, 1 for no margin, and 2 for minimum margin.
* `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`,
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height`
and `width` in microns.
* `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100.
* `pageRanges` Record<string, number> (optional) - The page range to print.
* `from` Number - the first page to print.
* `to` Number - the last page to print (inclusive).
* `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`,
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height`
* `printBackground` Boolean (optional) - Whether to print CSS backgrounds.
* `printSelectionOnly` Boolean (optional) - Whether to print selection only.
* `landscape` Boolean (optional) - `true` for landscape, `false` for portrait.
Returns `Promise<Buffer>` - Resolves with the generated PDF data.
@ -1324,7 +1333,9 @@ By default, an empty `options` will be regarded as:
marginsType: 0,
printBackground: false,
printSelectionOnly: false,
landscape: false
landscape: false,
pageSize: 'A4',
scaleFactor: 100
}
```

View file

@ -556,14 +556,21 @@ Prints `webview`'s web page. Same as `webContents.print([options])`.
### `<webview>.printToPDF(options)`
* `options` Object
* `headerFooter` Record<string, string> (optional) - the header and footer for the PDF.
* `title` String - The title for the PDF header.
* `url` String - the url for the PDF footer.
* `landscape` Boolean (optional) - `true` for landscape, `false` for portrait.
* `marginsType` Integer (optional) - Specifies the type of margins to use. Uses 0 for
default margin, 1 for no margin, and 2 for minimum margin.
* `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`,
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height`
and `width` in microns.
* `scaleFactor` Number (optional) - The scale factor of the web page. Can range from 0 to 100.
* `pageRanges` Record<string, number> (optional) - The page range to print.
* `from` Number - the first page to print.
* `to` Number - the last page to print (inclusive).
* `pageSize` String | Size (optional) - Specify page size of the generated PDF. Can be `A3`,
`A4`, `A5`, `Legal`, `Letter`, `Tabloid` or an Object containing `height`
* `printBackground` Boolean (optional) - Whether to print CSS backgrounds.
* `printSelectionOnly` Boolean (optional) - Whether to print selection only.
* `landscape` Boolean (optional) - `true` for landscape, `false` for portrait.
Returns `Promise<Uint8Array>` - Resolves with the generated PDF data.