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

bin+lib html2pdf

使用无头 Chrome 浏览器将 HTML 转换为 PDF

11 个版本 (6 个重大变更)

0.7.1 2024年3月12日
0.7.0 2023年10月17日
0.6.1 2023年10月7日
0.6.0 2023年1月16日
0.3.1 2021年7月26日

#381 in 编码

Download history 18/week @ 2024-04-10 18/week @ 2024-04-17 37/week @ 2024-04-24 22/week @ 2024-05-01 27/week @ 2024-05-08 26/week @ 2024-05-15 23/week @ 2024-05-22 12/week @ 2024-05-29 33/week @ 2024-06-05 21/week @ 2024-06-12 15/week @ 2024-06-19 13/week @ 2024-06-26 6/week @ 2024-07-03 6/week @ 2024-07-10 30/week @ 2024-07-17 95/week @ 2024-07-24

每月下载量 138

Apache-2.0 OR MIT

23KB
429

html2pdf

Docs Crates.io

仅是创建 PDF 的命令行工具,基于 headless_chrome 包。

安装

需要 Rust 工具链: https://rustup.rs/.

cargo install html2pdf

使用方法

html2pdf path/to/file.html

要移除日志,设置环境变量 RUST_LOGnone

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

选项

只需运行 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

依赖项

~9–20MB
~314K SLoC