PrecisionPDF on the command line
Use the precisionpdf command in scripts, background jobs, or an application that launches a separate process.
Install
Install Rust and Cargo, then install the CLI:
cargo install precisionpdf-cli
precisionpdf --version
Cargo installs the executable in its binary directory. If your shell cannot find precisionpdf, add that directory to your PATH and open a new terminal.
Convert a document
Pass the input first and the output path second:
precisionpdf document.html document.pdf
The input can be a local path or an HTTP(S) URL. The output is a PDF file. Use the getting-started document for a complete example.
precisionpdf https://example.com/report.html report.pdf
Render dynamic templates to HTML before conversion. Input JavaScript is not executed.
Set page size and margins
Use CSS for page geometry:
@page { size: A4; margin: 18mm; }
h2 { break-after: avoid; }
Link stylesheets in the HTML or pass additional stylesheets with --stylesheet:
precisionpdf --stylesheet print.css document.html document.pdf
The option can be repeated. Command-line stylesheets use the CSS user origin; normal declarations do not override explicit author declarations. Put the document’s primary styles in the HTML or its linked stylesheets.
Resolve fonts and images
Relative asset URLs are resolved from the input document’s location. Set --base-url to use a different base:
precisionpdf --base-url ./assets/ document.html document.pdf
Package fonts, images, and stylesheets with your document for offline rendering. Remote assets require network access.
Common options
| Option | Purpose |
|---|---|
--stylesheet PATH | Add a user stylesheet; repeat for multiple stylesheets. |
--base-url LOCATION | Set the base location for relative resources. |
--timeout SECONDS | Set a positive time limit for each HTTP(S) resource request. |
--no-http-redirects | Reject redirects when loading remote resources. |
--allow-fetch-errors | Continue when optional resources fail to load. |
--full-fonts | Embed full font programs when their embedding permissions allow it. |
--debug | Show diagnostic output, including rendering details. |
--info | Print host information without rendering a document. |
--help | Show the command’s complete usage and options. |
Resource loading errors fail the conversion by default. Use --allow-fetch-errors only when a missing optional image or stylesheet is acceptable; it does not make an unreadable input document usable.
Diagnose a problem
Run the same document with diagnostics enabled:
precisionpdf --debug document.html document.pdf
precisionpdf --info
Check font availability, relative paths, file permissions, and remote resource access in the environment that runs the command. Handle a nonzero process exit status as a failed conversion.
Choose an application integration when application code is a better fit.