PDFluent has no native dependencies. The Docker image is small and requires no additional apt packages.
# Dockerfile
FROM rust:1.78-slim AS builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
COPY --from=builder /app/target/release/pdf-processor /usr/local/bin/
ENTRYPOINT ["pdf-processor"]Your binary reads PDF bytes from stdin or a file path passed as an argument and writes results to stdout.
# Cargo.toml
[package]
name = "pdf-processor"
version = "0.1.0"
edition = "2021"
[dependencies]
pdfluent = "0.9"Accept the file path as a command-line argument. Process the document and print results to stdout.
// src/main.rs
use pdfluent::PdfDocument;
use std::env;
fn main() -> pdfluent::Result<()> {
let path = env::args().nth(1).expect("usage: pdf-processor <file.pdf>");
let doc = PdfDocument::open(&path)?;
println!("pages: {}", doc.page_count());
println!("title: {:?}", doc.metadata().title());
println!("chars: {}", doc.extract_text()?.len());
Ok(())
}The builder stage compiles the binary. The final stage copies only the binary into a minimal debian image. No Rust toolchain ships in the final image.
# Dockerfile
FROM rust:1.78-slim AS builder
WORKDIR /app
# Cache dependencies first
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main(){}" > src/main.rs
RUN cargo build --release
RUN rm -f target/release/deps/pdf_processor*
# Build the real binary
COPY src ./src
RUN cargo build --release
# Final image
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/pdf-processor /usr/local/bin/
ENTRYPOINT ["pdf-processor"]Build the image and run it with a test PDF mounted as a volume.
docker build -t pdf-processor:latest .
# Run with a local PDF
docker run --rm -v "$(pwd)/samples:/data" pdf-processor:latest /data/test.pdfIf your final base image is scratch or alpine, build a statically linked musl binary. This eliminates the glibc version dependency.
# Dockerfile (scratch variant)
FROM rust:1.78-slim AS builder
RUN rustup target add x86_64-unknown-linux-musl
RUN apt-get update && apt-get install -y musl-tools
WORKDIR /app
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl
FROM scratch
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/pdf-processor /
ENTRYPOINT ["/pdf-processor"]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.