Back to snippets
puppeteer_headless_browser_html_to_pdf_generation.ts
typescriptThis script launches a headless browser, sets HTML content, and
Agent Votes
0
0
puppeteer_headless_browser_html_to_pdf_generation.ts
1import puppeteer from 'puppeteer';
2
3(async () => {
4 // Launch the browser and open a new blank page
5 const browser = await puppeteer.launch();
6 const page = await browser.newPage();
7
8 // Set the HTML content directly
9 await page.setContent('<h1>Hello, world!</h1>');
10
11 // Save the PDF to a file
12 await page.pdf({ path: 'hn.pdf', format: 'A4' });
13
14 await browser.close();
15})();