How-to guides/Document Info

Read the PDF spec version from a document in Rust

Useful for pre-flight checks, compatibility filtering, and document auditing pipelines.

rust
use pdfluent::PdfDocument;

fn main() -> pdfluent::Result<()> {
    let doc = PdfDocument::open("document.pdf")?;
    let version = doc.pdf_version();

    println!("PDF version: {}.{}", version.major(), version.minor());
    // Example output: PDF version: 1.7

    if version < pdfluent::PdfVersion::V1_6 {
        eprintln!("Warning: document uses an older PDF version. AES encryption not supported.");
    }

    Ok(())
}
Install:cargo add pdfluentDownload SDK →

Step by step

1

Add PDFluent to Cargo.toml

The base crate includes all document metadata and version inspection functions.

rust
# Cargo.toml
[dependencies]
pdfluent = "0.9"
2

Open the document and call pdf_version()

pdf_version() reads the %PDF-x.y header from the first 8 bytes of the file. It does not require full document parsing.

rust
use pdfluent::PdfDocument;

let doc = PdfDocument::open("document.pdf")?;
let version = doc.pdf_version();

println!("{}.{}", version.major(), version.minor());
3

Compare versions with the PdfVersion enum

Use predefined constants to write readable version checks. PdfVersion implements PartialOrd.

rust
use pdfluent::PdfVersion;

let v = doc.pdf_version();

match v {
    PdfVersion::V1_0 => println!("Very old document"),
    PdfVersion::V1_4 => println!("PDF 1.4 - supports transparency"),
    PdfVersion::V1_5 => println!("PDF 1.5 - supports object streams"),
    PdfVersion::V1_6 => println!("PDF 1.6 - supports AES-128"),
    PdfVersion::V1_7 => println!("PDF 1.7 - supports AES-256"),
    PdfVersion::V2_0 => println!("PDF 2.0 - latest standard"),
    _ => println!("Other version: {}.{}", v.major(), v.minor()),
}
4

Read version without fully opening the document

Use PdfDocument::peek_version() to read only the header bytes. This is faster when you need to filter files before loading them.

rust
use pdfluent::PdfDocument;

let version = PdfDocument::peek_version("document.pdf")?;
println!("PDF {}.{}", version.major(), version.minor());

// Only load documents that are at least PDF 1.6
if version >= pdfluent::PdfVersion::V1_6 {
    let doc = PdfDocument::open("document.pdf")?;
    // ...
}

Notes and tips

  • The version in the %PDF header is the declared version. Some tools update the DocumentCatalog Version entry without changing the header. PDFluent returns the higher of the two values.
  • PDF 2.0 (ISO 32000-2) is the current standard. PDF 1.7 (ISO 32000-1) is still the most common version in real-world documents.
  • Versions below 1.4 do not support transparency groups. Versions below 1.5 do not support cross-reference streams.

Why PDFluent for this

Pure Rust

No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.

Memory safe

Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.

Runs anywhere

Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.

Frequently asked questions