mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
20 lines
465 B
Markdown
20 lines
465 B
Markdown
|
# PDF generation
|
||
|
|
||
|
For printing PDFs use [`Page.pdf()`](https://pptr.dev/api/puppeteer.page.pdf).
|
||
|
|
||
|
```ts
|
||
|
const browser = await puppeteer.launch();
|
||
|
const page = await browser.newPage();
|
||
|
await page.goto('https://news.ycombinator.com', {
|
||
|
waitUntil: 'networkidle2',
|
||
|
});
|
||
|
// Saves the PDF to hn.pdf.
|
||
|
await page.pdf({
|
||
|
path: 'hn.pdf',
|
||
|
});
|
||
|
|
||
|
await browser.close();
|
||
|
```
|
||
|
|
||
|
By default, the [`Page.pdf()`](https://pptr.dev/api/puppeteer.page.pdf) waits for fonts to be loaded.
|