Skip to content

A simple NPM package to convert HTML to PDF for Node applications by using Puppeteer

License

Notifications You must be signed in to change notification settings

cityssm/pdf-puppeteer

 
 

Repository files navigation

PDF-Puppeteer

npm (scoped) Code Climate maintainability codecov DeepSource

A simple npm package to convert HTML to PDF for Node.js applications by using Puppeteer.

Based on the work in westmonroe/pdf-puppeteer. Forked to manage dependencies, switch to ESM, and eliminate the callback function.

Installation

npm install @cityssm/pdf-puppeteer

Usage

import { convertHTMLToPDF } from "@cityssm/pdf-puppeteer";

/**
 * Usage
 * @param html - This is the HTML to be converted to a PDF.
 * @param [pdfOptions] - Optional parameter to pass in Puppeteer PDF options.
 * @param [pdfPuppeteerOptions] - Optional parameter to pass in PDF Puppeteer options.
 */
const pdfBuffer = await convertHTMLToPDF(html, pdfOptions, pdfPuppeteerOptions);

// Do something with the PDF, like send it as the response.
res.setHeader("Content-Type", "application/pdf");
res.send(pdfBuffer);

The convertHTMLToPDF() function takes the three parameters detailed above.

For more information on the available Puppeteer options for PDFs, take a look at Puppeteer's Page PDF Options.

PDF Puppeteer Options

Option Description Default Value
cacheBrowser Whether or not the Puppeter browser instance should be saved between PDFs. false
remoteContent Whether or not the HTML contains remote content. true
htmlIsUrl Whether or not the html parameter is actually a URL that should be navigated to. false

About

A simple NPM package to convert HTML to PDF for Node applications by using Puppeteer

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Languages

  • TypeScript 53.7%
  • JavaScript 46.3%