Useful for pre-flight checks, compatibility filtering, and document auditing pipelines.
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(())
}The base crate includes all document metadata and version inspection functions.
# Cargo.toml
[dependencies]
pdfluent = "0.9"pdf_version() reads the %PDF-x.y header from the first 8 bytes of the file. It does not require full document parsing.
use pdfluent::PdfDocument;
let doc = PdfDocument::open("document.pdf")?;
let version = doc.pdf_version();
println!("{}.{}", version.major(), version.minor());Use predefined constants to write readable version checks. PdfVersion implements PartialOrd.
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()),
}Use PdfDocument::peek_version() to read only the header bytes. This is faster when you need to filter files before loading them.
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")?;
// ...
}No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.