Catalog npm
PACKAGE EXPLORERView in registry

2pdf

npm

HTML to PDF command line tool

Versions collected9
Direct dependencies1From release 0.3.0
Last observed20 Oct, 19:17 UTC

README

Current package documentation

2pdf

Command line tool for creating PDFs from HTML files.

Based on puppeteer.

Install

npm i -g 2pdf

Usage

2pdf input.html output.pdf

Programmatic usage

Install locally with npm i 2pdf, then call pdf(input, output, options). Local HTML paths and HTTP/HTTPS URLs are supported. Options are optional.

var pdf = require('2pdf')

async function run() {
  try {
    await pdf('invoice.html', 'invoice.pdf', { format: 'A4' })
    await pdf('https://example.com', 'page.pdf')
  } catch (err) {
    console.error(err.message)
  }
}

run()

The Promise resolves when the PDF is written. It rejects for HTTP status 400 or higher on the final page response, navigation failures, or PDF write errors. Redirects are followed. The browser is closed after conversion or failure. The CLI reports these failures with exit code 1.

Both interfaces enable headers/footers and background printing by default. Config file options override defaults, and API options override config options. The output argument always takes precedence over the path option.

Configuration

PDF options can be set in 2pdf.json. The first file found is used, searching in the current directory, your home directory, then ~/.config/. Invalid JSON is reported as an error. YAML configuration is no longer supported. The command-line output path takes precedence over a configured path.

{
  "format": "A4",
  "printBackground": true,
  "displayHeaderFooter": false
}

Tests

Requires Node.js 18 or newer. Install dependencies with npm install, then run npm test. Tests include real Chromium conversions using local fixtures and a local HTTP server; no external websites are needed.

Troubleshooting

On Debian systems you need these libraries installed:

apt install libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0

MIT Licensed. Enjoy!

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 9

Collected releases
VersionPublishedDirect dependenciesOpen version
0.3.0Registry latest26 Sept 20261
0.2.629 Sept 20242
0.2.51 Dec 20232
0.2.43 May 20232
0.2.33 Mar 20232
0.2.215 Mar 20222
0.2.115 Mar 20222
0.2.015 Mar 20222
0.1.015 Mar 20222

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
eldoy/2pdf

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:17 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:1d99c21d43e30454ebfe593837d5e02be363ad65e511cb09739b1a3292862219