pptrhtmltopdf

0.4.1 • Public • Published

pptrhtmltopdf

Convert HTML to PDF using Chrome (Puppeteer)

Export PDF from Websites or HTML Files.

Alterative of wkhtmltopdf but pptrhtmltopdf uses Headless Chrome.

  • Add cover page 🆗
  • Add backcover page 🆗
  • Generate TOC page 🆗
  • Support multi HTML 🆗
  • Support local HTML 🆗
  • Support Website 🆗

Output PDF Example: examples/output-examples.pdf

Install

npm install pptrhtmltopdf

Usage

NAME
    pptrhtmltopdf [OPTIONS] [FILE or URL]...

    Convert HTML to PDF using Chrome (Puppeteer)

DESCRIPTION
    --output=[FILE]    Save PDF to [FILE]
    --cover=[FILE]     Use [FILE] to cover
    --backcover=[FILE] Use [FILE] to backcover
    --generate-toc     Generate TOC(Table of Contents)
    --no-sandbox       Disable Chrome's sandboxing
    --debug            Run in DEBUG mode
    --version          Show version
    --help             Show this help

Run pptrhtmltopdf or node_modules/.bin/pptrhtmltopdf

Example

Capture https://github.com/netmarkjp/pptrhtmltopdf to ./output.pdf

pptrhtmltopdf https://github.com/netmarkjp/pptrhtmltopdf

Capture https://github.com/netmarkjp/pptrhtmltopdf/blob/master/README.md and https://github.com/netmarkjp/pptrhtmltopdf/blob/master/LICENSE to docs.pdf with TOC

pptrhtmltopdf --generate-toc --output=docs.pdf \
    https://github.com/netmarkjp/pptrhtmltopdf/blob/master/README.md \
    https://github.com/netmarkjp/pptrhtmltopdf/blob/master/LICENSE

Run on Docker

docker run --rm -it -v $(pwd):/mnt -w /mnt netmarkjp/pptrhtmltopdf \
    pptrhtmltopdf --no-sandbox \
        --generate-toc \
        --output=/mnt/output.pdf \
        https://github.com/netmarkjp/pptrhtmltopdf/blob/master/README.md \
        https://github.com/netmarkjp/pptrhtmltopdf/blob/master/LICENSE

Development

# build
npm run-script build
# run
npm run-script run -- \
    --debug \
    --generate-toc \
    --output=/path/to/output.pdf \
    --cover=/path/to/cover.html \
    --backcover=/path/to/backcover.html \
    /path/to/i.html \
    /path/to/ii.html \
    /path/to/iii.html

NOTE:

  • Cover(Back Cover) and TOC are not counted within page number.

Stack

  • Node 18
  • Puppeteer 20.7
  • pdf-lib 1.2
  • pdf-tex-extract 1.5
  • TypeScript 5.1

TODO

High

  • CI/CD

Moderate

  • Footer formatting
  • Header
  • TOC customise
  • PDF page size customise

Readme

Keywords

none

Package Sidebar

Install

npm i pptrhtmltopdf

Weekly Downloads

0

Version

0.4.1

License

Apache-2.0

Unpacked Size

65.8 kB

Total Files

11

Last publish

Collaborators

  • netmarkjp