@cityssm/pdf-puppeteer
v6.4.1
Published
Converts URLs and HTML to PDFs using Puppeteer.
Maintainers
Readme
PDF Puppeteer
Converts URLs and HTML to PDFs using Puppeteer.
Based on the work in westmonroe/pdf-puppeteer.
Installation
npm install @cityssm/pdf-puppeteerUsage
import PdfPuppeteer from '@cityssm/pdf-puppeteer'
// Initialize PDF Puppeteer.
const pdfPuppeteer = new PdfPuppeteer(pdfPuppeteerOptions)
// Convert a website to a PDF.
const pdfBufferFromUrl = await pdfPuppeteer.fromUrl(url, pdfOptions)
// Convert HTML to a PDF.
const pdfBufferFromHTML = await pdfPuppeteer.fromHtml(html, pdfOptions)
// Do something with the PDF, like send it as the response.
res.setHeader('Content-Type', 'application/pdf')
res.send(pdfBufferFromHTML)For more information on the available Puppeteer options for PDFs (pdfOptions),
take a look at Puppeteer's Page PDF Options.
PDF Puppeteer Options
| Option | Description | Default Value |
| --------------------- | ---------------------------------------------------------------------------------------------- | ------------- |
| browser | The web browser to use for PDF generation, either "chrome" or "firefox" | "chrome" |
| disableSandbox | Required in some secure environments. | false |
| usePackagePuppeteer | Use the version of Puppeteer installed in the package rather than @cityssm/puppeteer-launch. | false |
Related Project
@cityssm/paper-sizes Retrieves exact dimensions for common paper sizes, including North American (ANSI and ARCH) and ISO.
@cityssm/puppeteer-launch Launches Puppeteer, falling back to system browsers when the cached ones aren't working or aren't available.
