Skip to content

Rust TUI tool that compresses PDF files while preserving quality.

Notifications You must be signed in to change notification settings

Dann1y/pdf_squish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pdf-squish

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.

Rust

Features

  • 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

Installation

git clone https://github.com/Dann1y/pdf_squish.git
cd pdf_squish
cargo build --release

The binary will be at target/release/pdf-squish.

Usage

# 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"

TUI Controls

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

Compression Levels

Strategy Light Standard Aggressive
Stream recompression (zlib best)
Empty stream removal
Unused object cleanup
Metadata stripping
Object renumbering
Duplicate stream dedup

How It Works

PDF files store content as streams — compressed binary data for text, fonts, vector graphics, etc. Many PDF generators use suboptimal compression settings.

pdf-squish:

  1. Parses the PDF object tree via lopdf
  2. Identifies recompressible streams (FlateDecode, LZW, uncompressed)
  3. Decompresses each stream, then re-encodes with flate2 at maximum compression (zlib level 9)
  4. Optionally removes dead objects, metadata, and duplicate streams
  5. Writes the optimized PDF as {filename}_compressed.pdf

The original file is never modified.

Dependencies

License

MIT

About

Rust TUI tool that compresses PDF files while preserving quality.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages