Skip to content

Instantly share code, notes, and snippets.

@fforres
Created March 28, 2022 18:41
Show Gist options
  • Save fforres/2b0b7f32d0ab6ce94c9bb9264091c1f9 to your computer and use it in GitHub Desktop.
Save fforres/2b0b7f32d0ab6ce94c9bb9264091c1f9 to your computer and use it in GitHub Desktop.
import puppeteer from "puppeteer"
async function generatePdf(htmlContent) {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setContent(htmlContent);
const pdf = await page.pdf({ format: 'A4' });
const pdfBuffer = await page.pdf();
await page.close();
await browser.close();
return pdfBuffer;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment