#headless-chrome #pdf #convert-html #browser #local

bin+lib html2pdf

Convert HTML to PDF using a Headless Chrome browser

12 releases (7 breaking)

0.8.0 Nov 24, 2024
0.7.1 Mar 12, 2024
0.7.0 Oct 17, 2023
0.6.0 Jan 16, 2023
0.3.1 Jul 26, 2021

#788 in Command line utilities

Download history 3/week @ 2024-08-24 7/week @ 2024-08-31 16/week @ 2024-09-07 16/week @ 2024-09-14 17/week @ 2024-09-21 24/week @ 2024-09-28 19/week @ 2024-10-05 25/week @ 2024-10-12 15/week @ 2024-10-19 5/week @ 2024-10-26 9/week @ 2024-11-02 11/week @ 2024-11-09 20/week @ 2024-11-16 156/week @ 2024-11-23 15/week @ 2024-11-30 97/week @ 2024-12-07

290 downloads per month

Apache-2.0 OR MIT

26KB
462 lines

html2pdf

Docs Crates.io

Just a CLI over the headless_chrome crate to create PDF.

Install

Need the Rust toolchain: https://rustup.rs/.

cargo install html2pdf

Usage

html2pdf path/to/file.html

To remove logs, set the env var RUST_LOG to none :

RUST_LOG="none" html2pdf path/to/file.html

Options

Just run html2pdf --help :

html2pdf 0.4.0
Generate a PDF from a local HTML file using a headless chrome

USAGE:
    html2pdf [FLAGS] [OPTIONS] <input>

FLAGS:
        --background       Allow print background
    -h, --help             Prints help information
        --landscape        Use landscape mode
        --disable-sandbox  Disable Chrome sandbox. Not recommended, unless running on docker

    -V, --version          Prints version information

OPTIONS:
        --footer <footer>  HTML template for the print footer. Should use the same format as the headerTemplate
        --header <header>  HTML template for the print header. Should be valid HTML markup with following classes used
                           to inject printing values into them: date for formatted print date, title for document
                           title, url for document location, pageNumber for current page number, totalPages for total
                           pages in the document. For example, `<span class=title></span>` would generate span
                           containing the title
        --margin <margin>  Margin in inches You can define margin like this: '0.4' the value is applied for all side,
                                  '0.4 0.4' : first value is applied for top and bottom, second for left and right, '0.4 0.4
                                  0.4 0.4' : first value is applied for top then, right, then bottom, and last for left
    -o, --output <output>  Output file. By default, just change the input extension to PDF
        --paper <paper>    Paper size. Supported values: A4, Letter, A3, Tabloid, A2, A1, A0, A5, A6
        --range <range>    Paper ranges to print, e.g. '1-5, 8, 11-13'
        --scale <scale>    Scale, default to 1.0
        --wait <wait>      Time to wait in ms before printing. Examples: 150ms, 10s

ARGS:
    <input>    Input HTML file

Dependencies

~11–26MB
~341K SLoC