| Crates.io | pdfcrop |
| lib.rs | pdfcrop |
| version | 0.1.0 |
| created_at | 2025-11-23 19:48:07.070224+00 |
| updated_at | 2025-11-23 19:48:07.070224+00 |
| description | PDF cropping library and command-line tool with rendering-based bbox detection |
| homepage | |
| repository | https://github.com/pdfcrop/pdfcrop |
| max_upload_size | |
| id | 1946924 |
| size | 266,456 |
A Rust library and CLI tool for cropping PDF files with rendering-based automatic bounding box detection.
Inspired by the original pdfcrop from TeX Live.
Web app using WASM available at pdfcrop.github.io.
# Install
cargo install --path .
# Basic crop (auto-detect bbox)
pdfcrop input.pdf output.pdf
# With margins
pdfcrop --margins "10" input.pdf output.pdf
# Verbose mode to see detection details
pdfcrop --verbose input.pdf output.pdf
# Custom bbox
pdfcrop --bbox "50 50 500 700" input.pdf output.pdf
# Add content clipping (adds clipping path to stream - increases file size)
pdfcrop --clip input.pdf output.pdf
# Auto-shrink manual bbox to actual content (removes remaining margins)
pdfcrop --bbox "0 0 612 792" --shrink-to-content input.pdf output.pdf
use pdfcrop::{crop_pdf, CropOptions, Margins};
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let pdf_data = fs::read("input.pdf")?;
let options = CropOptions {
margins: Margins::uniform(10.0),
verbose: true,
..Default::default()
};
let cropped = crop_pdf(&pdf_data, options)?;
fs::write("output.pdf", cropped)?;
Ok(())
}
# Generate test PDFs with shapes and crop them
cargo run --example crop_shapes_pdf
# Download a real PDF and crop it
cargo run --example crop_online_pdf
# Build
cargo build --release
# Run tests
cargo test
# Format and lint
cargo fmt
cargo clippy
MIT OR Apache-2.0