Skip to content

Saves a webpage as PDF using Chrome's Puppeteer

Notifications You must be signed in to change notification settings

pierrecholhot/krldf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

krldf

Saves a webpage as PDF using Chrome's Puppeteer.

Install

npm install pierrecholhot/krldf

Usage

const krldf = require('krldf')

krldf({ url: 'https://www.google.com/' })

with promises

Example in examples/node-promises.js

with async/await

Example in examples/node-async.js

CLI

Example in examples/cli.sh

./node_modules/krldf/cli.js --url="https://www.google.com/"
krldf --url="https://www.google.com/"

or via npx

npx krldf --url="https://www.google.com/"

Options

url

Type : string
Default : about:blank
Description : URL of the page to be converted.
The url should include scheme, e.g. https://.

filePath

Type : string
Default : result.pdf
Description : The file path to save the PDF to.
If filePath is a relative path, then it is resolved relative to current working directory.

captureDelay

Type : number
Default : 2000
Description : Number of ms to wait after navigation succeeded.
Useful when waiting for authentication services.

captureWhen

Type : string
Default : networkidle0
Description : When to consider navigation succeeded. More on page.goTo({ waitUntil }).

  • load consider navigation to be finished when the load event is fired.
  • domcontentloaded consider navigation to be finished when the DOMContentLoaded event is fired.
  • networkidle0 consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
  • networkidle2 consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

viewportWidth

Type : number
Default : 2560
Description : Width of the capture viewport.

viewportHeight

Type : number
Default : 1440
Description : Height of the capture viewport.

paperFormat

Type : string
Default : A4
Options : Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6

landscapeMode

Type : boolean
Default : false
Description : Enable paper landscape orientation.

printHeaderTemplate
printFooterTemplate

Type : string
Default : (empty strings)
Description : HTML templates for the print header and print footer.
Should be valid HTML markup with following classes used to inject printing values into them :

  • date formatted print date
  • title document title
  • url document location
  • pageNumber current page number
  • totalPages total pages in the document

browserArgs

Type : array
Default : []
Description : Additional arguments to pass to the browser instance.
The list of Chromium flags can be found here.

About

Saves a webpage as PDF using Chrome's Puppeteer

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published