docs: document printToPDF
generateDocumentOutline
option (#41156)
* doc: document printToPDF generateDocumentOutline option * doc: ready event to whenReady
This commit is contained in:
parent
fc917985ae
commit
6786fde576
4 changed files with 20 additions and 13 deletions
|
@ -1614,6 +1614,7 @@ win.webContents.print(options, (success, errorType) => {
|
||||||
* `footerTemplate` string (optional) - HTML template for the print footer. Should use the same format as the `headerTemplate`.
|
* `footerTemplate` string (optional) - HTML template for the print footer. Should use the same format as the `headerTemplate`.
|
||||||
* `preferCSSPageSize` boolean (optional) - Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
|
* `preferCSSPageSize` boolean (optional) - Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
|
||||||
* `generateTaggedPDF` boolean (optional) _Experimental_ - Whether or not to generate a tagged (accessible) PDF. Defaults to false. As this property is experimental, the generated PDF may not adhere fully to PDF/UA and WCAG standards.
|
* `generateTaggedPDF` boolean (optional) _Experimental_ - Whether or not to generate a tagged (accessible) PDF. Defaults to false. As this property is experimental, the generated PDF may not adhere fully to PDF/UA and WCAG standards.
|
||||||
|
* `generateDocumentOutline` boolean (optional) _Experimental_ - Whether or not to generate a PDF document outline from content headers. Defaults to false.
|
||||||
|
|
||||||
Returns `Promise<Buffer>` - Resolves with the generated PDF data.
|
Returns `Promise<Buffer>` - Resolves with the generated PDF data.
|
||||||
|
|
||||||
|
@ -1624,11 +1625,12 @@ The `landscape` will be ignored if `@page` CSS at-rule is used in the web page.
|
||||||
An example of `webContents.printToPDF`:
|
An example of `webContents.printToPDF`:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { BrowserWindow } = require('electron')
|
const { app, BrowserWindow } = require('electron')
|
||||||
const fs = require('node:fs')
|
const fs = require('node:fs')
|
||||||
const path = require('node:path')
|
const path = require('node:path')
|
||||||
const os = require('node:os')
|
const os = require('node:os')
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
const win = new BrowserWindow()
|
const win = new BrowserWindow()
|
||||||
win.loadURL('https://github.com')
|
win.loadURL('https://github.com')
|
||||||
|
|
||||||
|
@ -1644,6 +1646,7 @@ win.webContents.on('did-finish-load', () => {
|
||||||
console.log(`Failed to write PDF to ${pdfPath}: `, error)
|
console.log(`Failed to write PDF to ${pdfPath}: `, error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
See [Page.printToPdf](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF) for more information.
|
See [Page.printToPdf](https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF) for more information.
|
||||||
|
|
|
@ -611,6 +611,7 @@ Prints `webview`'s web page. Same as `webContents.print([options])`.
|
||||||
* `footerTemplate` string (optional) - HTML template for the print footer. Should use the same format as the `headerTemplate`.
|
* `footerTemplate` string (optional) - HTML template for the print footer. Should use the same format as the `headerTemplate`.
|
||||||
* `preferCSSPageSize` boolean (optional) - Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
|
* `preferCSSPageSize` boolean (optional) - Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
|
||||||
* `generateTaggedPDF` boolean (optional) _Experimental_ - Whether or not to generate a tagged (accessible) PDF. Defaults to false. As this property is experimental, the generated PDF may not adhere fully to PDF/UA and WCAG standards.
|
* `generateTaggedPDF` boolean (optional) _Experimental_ - Whether or not to generate a tagged (accessible) PDF. Defaults to false. As this property is experimental, the generated PDF may not adhere fully to PDF/UA and WCAG standards.
|
||||||
|
* `generateDocumentOutline` boolean (optional) _Experimental_ - Whether or not to generate a PDF document outline from content headers. Defaults to false.
|
||||||
|
|
||||||
Returns `Promise<Uint8Array>` - Resolves with the generated PDF data.
|
Returns `Promise<Uint8Array>` - Resolves with the generated PDF data.
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,7 @@ WebContents.prototype.printToPDF = async function (options) {
|
||||||
pageRanges: checkType(options.pageRanges ?? '', 'string', 'pageRanges'),
|
pageRanges: checkType(options.pageRanges ?? '', 'string', 'pageRanges'),
|
||||||
preferCSSPageSize: checkType(options.preferCSSPageSize ?? false, 'boolean', 'preferCSSPageSize'),
|
preferCSSPageSize: checkType(options.preferCSSPageSize ?? false, 'boolean', 'preferCSSPageSize'),
|
||||||
generateTaggedPDF: checkType(options.generateTaggedPDF ?? false, 'boolean', 'generateTaggedPDF'),
|
generateTaggedPDF: checkType(options.generateTaggedPDF ?? false, 'boolean', 'generateTaggedPDF'),
|
||||||
|
generateDocumentOutline: checkType(options.generateDocumentOutline ?? false, 'boolean', 'generateDocumentOutline'),
|
||||||
...parsePageSize(options.pageSize ?? 'letter')
|
...parsePageSize(options.pageSize ?? 'letter')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2039,7 +2039,9 @@ describe('webContents module', () => {
|
||||||
pageRanges: { oops: 'im-not-the-right-key' },
|
pageRanges: { oops: 'im-not-the-right-key' },
|
||||||
headerTemplate: [1, 2, 3],
|
headerTemplate: [1, 2, 3],
|
||||||
footerTemplate: [4, 5, 6],
|
footerTemplate: [4, 5, 6],
|
||||||
preferCSSPageSize: 'no'
|
preferCSSPageSize: 'no',
|
||||||
|
generateTaggedPDF: 'wtf',
|
||||||
|
generateDocumentOutline: [7, 8, 9]
|
||||||
};
|
};
|
||||||
|
|
||||||
await w.loadURL('data:text/html,<h1>Hello, World!</h1>');
|
await w.loadURL('data:text/html,<h1>Hello, World!</h1>');
|
||||||
|
|
Loading…
Add table
Reference in a new issue