feat: improve callback value for webContents.print() (#19000)

Resolves #18980.

Adds granularity to the optional callback in webContents.print() by adding a failureType value in addition to the success boolean that differentiates between cancelled and failed print jobs.
This commit is contained in:
Shelley Vohr 2019-07-01 14:03:19 -07:00 committed by GitHub
parent 5154b95447
commit 21d04ed3f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 20 deletions

View file

@ -1249,6 +1249,7 @@ Returns [`PrinterInfo[]`](structures/printer-info.md).
* `vertical` Number (optional) - The vertical dpi.
* `callback` Function (optional)
* `success` Boolean - Indicates success of the print call.
* `failureReason` String - Called back if the print fails; can be `cancelled` or `failed`.
Prints window's web page. When `silent` is set to `true`, Electron will pick
the system's default printer if `deviceName` is empty and the default settings
@ -1259,6 +1260,15 @@ Calling `window.print()` in web page is equivalent to calling
Use `page-break-before: always;` CSS style to force to print to a new page.
Example usage:
```js
const options = { silent: true, deviceName: 'My-Printer' }
win.webContents.print(options, (success, errorType) => {
if (!success) console.log(errorType)
})
```
#### `contents.printToPDF(options)`
* `options` Object