A pure Rust TUI tool that compresses PDF files while preserving quality.
Recompresses streams with maximum deflate, removes unused objects and metadata, and deduplicates identical streams — all without touching image codecs.
- Stream recompression — Decompress and re-encode all FlateDecode/LZW streams at zlib level 9
- Safe — Never touches JPEG, JBIG2, or JPX image data
- Unused object cleanup — Removes unreferenced objects from the PDF tree
- Metadata stripping — Removes XMP, Info dictionary, and per-page metadata
- Stream deduplication — SHA-256 hashing to merge identical streams
- Interactive TUI — File browser, quality selector, real-time progress
git clone https://github.com/Dann1y/pdf_squish.git
cd pdf_squish
cargo build --releaseThe binary will be at target/release/pdf-squish.
# Launch TUI
cargo run --release
# Pre-fill input path
cargo run --release -- /path/to/file.pdf
# Glob pattern
cargo run --release -- "/path/to/docs/*.pdf"| Key | Action |
|---|---|
Tab / Shift+Tab |
Cycle focus: Input → Quality → File List |
Enter |
Load files / Start compression |
1 2 3 |
Select Light / Standard / Aggressive |
j k / ↑ ↓ |
Navigate file list |
d |
Remove selected file |
r |
Reset after completion |
q |
Quit |
| Strategy | Light | Standard | Aggressive |
|---|---|---|---|
| Stream recompression (zlib best) | ✓ | ✓ | ✓ |
| Empty stream removal | ✓ | ✓ | ✓ |
| Unused object cleanup | ✓ | ✓ | |
| Metadata stripping | ✓ | ✓ | |
| Object renumbering | ✓ | ✓ | |
| Duplicate stream dedup | ✓ |
PDF files store content as streams — compressed binary data for text, fonts, vector graphics, etc. Many PDF generators use suboptimal compression settings.
pdf-squish:
- Parses the PDF object tree via
lopdf - Identifies recompressible streams (FlateDecode, LZW, uncompressed)
- Decompresses each stream, then re-encodes with
flate2at maximum compression (zlib level 9) - Optionally removes dead objects, metadata, and duplicate streams
- Writes the optimized PDF as
{filename}_compressed.pdf
The original file is never modified.
- ratatui + crossterm — TUI
- lopdf — PDF manipulation
- flate2 — Compression
- tokio — Async runtime
- sha2 — Deduplication hashing
MIT