MiniPdf for Rust

August 30, 2026 · View on GitHub

crates.io docs.rs License

The experimental native Rust implementation of MiniPdf. It provides the reusable minipdf crate and the minipdf-cli package, whose installed binary is named minipdf.

Project portal · crates.io · API documentation · .NET implementation

The Rust implementation is under active development and is not yet feature-equivalent with MiniPdf for .NET. It currently converts XLSX and DOCX files. Use the .NET implementation for PPTX, content extraction, PDF merge, or broader production compatibility.

Requirements

  • Rust 1.82 or later
  • No Microsoft Office, LibreOffice, Adobe Acrobat, or .NET runtime at runtime

Library

Add the crate:

cargo add minipdf

Convert a file to a PDF on disk:

fn main() -> minipdf::Result<()> {
    minipdf::convert_to_pdf("report.docx", "report.pdf")?;
    Ok(())
}

Return PDF bytes instead:

let pdf = minipdf::convert_to_pdf_bytes("data.xlsx")?;

Override the output page size with a preset or custom dimensions:

let options = minipdf::ConversionOptions {
    page_size: Some(minipdf::PageSize::A4),
};
minipdf::convert_to_pdf_with_options("data.xlsx", "data.pdf", &options)?;

let custom = minipdf::ConversionOptions {
    page_size: Some(minipdf::PageSize::new(400.0, 500.0)?),
};
minipdf::convert_to_pdf_with_options("report.docx", "report.pdf", &custom)?;

Custom dimensions use PDF points, where 72 points equal one inch. XLSX conversion uses an explicit API override first, then the worksheet pageSetup paper size and orientation. A worksheet without a recognized page setup uses A4.

For a host with limited system fonts, register font bytes before conversion:

let font = std::fs::read("fonts/NotoSansSC-Regular.ttf")?;
minipdf::register_font("NotoSansSC", font);
minipdf::convert_to_pdf("report.docx", "report.pdf")?;

The public API also supports in-memory Office package bytes through convert_bytes_to_pdf and package inspection through detect_office_format.

Command Line

Install the CLI from crates.io:

cargo install minipdf-cli

Convert with an automatically selected output name:

minipdf report.docx

Specify an output path or font directory:

minipdf data.xlsx -o data.pdf
minipdf report.docx --fonts ./fonts
minipdf convert report.docx -o report.pdf

Select A4 or Letter paper, or provide custom dimensions in PDF points:

minipdf data.xlsx --paper-size a4
minipdf data.xlsx --paper-size letter
minipdf data.xlsx --page-width 400 --page-height 500

--paper-size cannot be combined with --page-width and --page-height. Custom width and height must be provided together.

Current Scope

CapabilityRust status
XLSX to PDFSupported; rendering coverage is expanding
DOCX to PDFSupported; rendering coverage is expanding
PPTX to PDFNot supported
PDF mergeNot supported
Markdown / JSON extractionNot supported
PDF outputPDF 1.4
FontsBuilt-in Helvetica and registered/system fallback fonts
Page sizeXLSX page setup, A4/Letter presets, or custom point dimensions
InterfacesRust crate and native CLI

The converter preserves sparse worksheet row positions, paginates wide sheets horizontally, and supports basic spreadsheet styling, drawing images, document text, and Unicode fallback fonts. Complex Office layout can still differ from the source application.

Development

The Rust implementation is an independent Cargo workspace:

minipdf-rs/
|-- Cargo.toml
`-- crates/
    |-- minipdf/       # Library API and conversion engine
    `-- minipdf-cli/   # CLI binary named minipdf

Run the standard checks from this directory:

cargo fmt --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo run -p minipdf-cli -- path\to\input.docx

Visual Benchmarks

Run shared fixtures against Microsoft 365 and LibreOffice from the repository root:

.\scripts\Run-Rust-Benchmark.ps1 -Suite classic -Format xlsx
.\scripts\Run-Rust-Benchmark.ps1 -Suite classic -Format docx
.\scripts\Run-Rust-Benchmark.ps1 -Suite issue -Format xlsx
.\scripts\Run-Rust-Benchmark.ps1 -Suite issue -Format docx
.\scripts\Run-Rust-Benchmark-Matrix.ps1 -MaxComparePages 1

The benchmark reuses the repository fixtures, references, and PDF comparison pipeline without executing the C# xUnit tests. Each run writes coverage data, Markdown and JSON reports, side-by-side images, and heatmaps under artifacts/rust-benchmark/<suite>/<format>.

Microsoft 365 is the primary reference used for text, visual, page-count, and overall scores. LibreOffice is generated on every run as an auxiliary reference and is included in the visual report without affecting those scores.

The matrix is generated at artifacts/rust-benchmark/benchmark_matrix.md and links to the fixture coverage and comparison reports from each run.

Publishing

Both packages are published to crates.io. Repository releases tagged rust-v<version> publish minipdf first and then minipdf-cli through GitHub Actions.

License

Apache License 2.0.