Get started with PrecisionPDF

Go from HTML and CSS to a PDF in a few steps. Choose the command line, Rust, or Python; each example uses the same document.

Install

Terminal

Install the command-line tool with Rust and Cargo, then check the installation:

cargo install precisionpdf-cli
precisionpdf --version
Rust

Create a project and add PrecisionPDF. Tokio provides the async runtime used in this example:

cargo new my-pdf
cd my-pdf
cargo add precisionpdf
cargo add tokio --features macros,rt
Python

Create and activate a virtual environment, then install the package:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install precisionpdf

On Windows, activate the environment with .venv\Scripts\Activate.ps1 in PowerShell. See the Python guide for more examples.

Create document.html

Save this as document.html in your working directory, or download the HTML:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Monthly report</title>
  <style>
    @page { size: A4; margin: 20mm; }
    body { font-family: serif; line-height: 1.5; }
    h1 { color: #407080; }
    table { width: 100%; border-collapse: collapse; }
    th, td { padding: 8px; text-align: left; }
    th { border-bottom: 1px solid #407080; }
  </style>
</head>
<body>
  <h1>Monthly report</h1>
  <p>A short report, ready to share.</p>
  <table>
    <tr><th scope="col">Project</th><th scope="col">Status</th></tr>
    <tr><td>Customer portal</td><td>Complete</td></tr>
    <tr><td>Documentation</td><td>Published</td></tr>
  </table>
</body>
</html>

Generate a PDF

Terminal

Convert the HTML file:

precisionpdf document.html document.pdf

Open document.pdf in your PDF viewer. For stylesheets, asset paths, and diagnostics, see the command-line guide.

Rust

Replace src/main.rs with:

use precisionpdf::{Html, PdfOptions, RenderOptions};
use std::fs::File;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut output = File::create("document.pdf")?;
    Html::from_file("document.html")
        .await?
        .write_pdf(
            &mut output,
            &RenderOptions::default(),
            &PdfOptions::default(),
        )
        .await?;
    Ok(())
}

Run cargo run, then open document.pdf. The Rust guide also covers HTML strings, in-memory output, and resource loading.

Python

Save this as render.py:

from precisionpdf import HTML

HTML(filename="document.html").write_pdf("document.pdf")

Run python render.py, then open document.pdf. The Python guide covers strings, byte output, and resource paths.

Next steps

Use @page to choose page dimensions and margins, and @font-face to package your own fonts. Generate dynamic content as HTML before passing it to the renderer.

Explore the documentation, or review the free core and document handling.