Catalog npm
Back to packageRELEASE DETAILS

0.2.3

npm

2pdf

HTML to PDF command line tool

Published3 Mar 2023
Direct dependencies2
Transitive dependenciesNot calculated

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.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
extras
Environment
{
  "local_name": "extras",
  "alias": false,
  "peer_metadata": null
}
^0.10.6runtime
puppeteer
Environment
{
  "local_name": "puppeteer",
  "alias": false,
  "peer_metadata": null
}
^19.7.2runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "c18ca18e0414a523ad35009fffa9ada0fe6a8620",
  "tarball": "https://registry.npmjs.org/2pdf/-/2pdf-0.2.3.tgz",
  "fileCount": 8,
  "integrity": "sha512-7egaSOYRIKK7vSdeqXK/RFSANblF6iDCvgxaLEYrR+Oi8XZqsvMecVrGv/IvcDXL3ZjfdrzL/SgUqHqkIFTsWQ==",
  "signatures": [
    {
      "sig": "MEUCIFnj2fy8KQQ72Txbq0mSlSlK81U9RBeB6iz7FbCmzkR3AiEAux/pSfFtqNHuocVEGqEDvRLbVfHpYvlKEXyNu/ItpNk=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 3558,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkAczZACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqB6A/+MI0eLXfejeG9RIzTi+hLRRPPbrX+1MfmxQhEHdCObbPv21IQ\r\n9KfwTiIJcdUjtXGJW4M/oGoby6IFOPNSdLq3v+haIKokaIMUcNECP0kb/2H8\r\n5N2vwd4EfmkroyqjlwXKtpsHbkYIGXa+PCCgMNCRcIOp93p/7mkGdCjEEbIh\r\nrfFPopCEAWauKs69+q43Ps1ArXpF1na7wqYeX5yfDuQqMNwvFsiyjiHm6A0z\r\nNc1cIvzBVe06IClEzfMTGQs63kkzUrFWfjq0TDDe9STYoROQCI4iA8wg/PvJ\r\nbR0kZHaBTWV9OpjkL+J1GP2zCTXUTAmT+yV1X2MhNBkbQ7rqu5wgddD/Qde9\r\nuvQFSfYshk2KQLLrWC3OwfypiXrMN0HZ5Baj7X2ThbkiWCl4xJibNXsFi3zP\r\nJ7n0QMhTFL2imG8po0A78U4MzaRz80NiaFkVYJRqmyREymTBjp6MNtmTQXiS\r\nQN4VKhlRKA7/kYaxQmr2XUHqozw0ZkrmIHxUW6Ihj6ohOQt1g8kSWaEyaIFU\r\nmN5Y5bRptylPVB8OCsQtL4Mtkp2SS6OnXByAJ+bSHPOhiBjiTjzxrsINc4F9\r\nNCEFkVJTERoBl/Hq/Q7sqfJrrkIXtX4w1pwUJtW9B111iXZ0sPgHUohbPsoQ\r\nIhT+a9ooQ0zieChWHKFfUNWmKAyQ/K//mNM=\r\n=DD1L\r\n-----END PGP SIGNATURE-----\r\n"
}

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_version:b2d2ce08f9a33d7f9c15ed7874989783c5142987f0e16d684c87ca4a4e95e7e2

Other collected versions

0.3.026 Sept0.2.629 Sept0.2.51 Dec0.2.43 May0.2.215 Mar0.2.115 MarView all collected versions →