Skip to content

Target-size PDF compression from the command line. Compress PDFs to an exact target size, 100% locally and privately.

License

Notifications You must be signed in to change notification settings

paradoxie/quantpdf-cli

QuantPDF CLI

QuantPDF CLI License: MIT Python 3.8+ PyPI version

🎯 Target-size PDF compression from the command line

Compress PDFs to an exact target size, locally and privately.

Features β€’ Installation β€’ Quick Start β€’ Documentation β€’ GUI Version

πŸ‡¨πŸ‡³ δΈ­ζ–‡


🌟 Why QuantPDF CLI?

Most PDF compression tools offer vague "Low/Medium/High" quality settings. QuantPDF CLI is different:

  • 🎯 Target-Oriented: Specify exact output size (e.g., "compress to 25MB")
  • πŸ”’ Privacy-First: 100% local processing, no uploads, no cloud
  • πŸ“Š Smart Optimization: Prioritizes text readability over aggressive downsizing
  • ⚑ Fast & Efficient: Optimized for large scanned PDFs
  • πŸ†“ Free & Open Source: MIT License, use anywhere

✨ Features

Core Capabilities

  • βœ… Exact target size - Set 25MB, get 25MB (Β±5% accuracy)
  • βœ… Local processing - Files never leave your machine
  • βœ… Smart compression - Maintains readability while reducing size
  • βœ… Multiple passes - Iterative optimization for better results
  • βœ… Flexible DPI - Choose from 100-300 DPI
  • βœ… Color modes - Color, Grayscale, or Black & White
  • βœ… Progress tracking - Real-time JSON progress output
  • βœ… Batch processing - Process multiple files via scripting

Perfect For

  • πŸ“„ Government forms with strict size limits (10-25MB)
  • πŸŽ“ Academic submissions and applications
  • πŸ’Ό Job applications with resume size caps
  • πŸ“ Archiving large scanned documents
  • πŸ“§ Email attachments with size restrictions

πŸ“¦ Installation

Via pip (Recommended)

pip install quantpdf-cli

From source

git clone https://github.com/paradoxie/quantpdf-cli.git
cd quantpdf-cli
pip install -r requirements.txt

System Requirements

  • Python: 3.8 or higher
  • Poppler: Required for PDF processing

Install Poppler:

macOS:

brew install poppler

Ubuntu/Debian:

sudo apt-get install poppler-utils

Windows: Download from Poppler for Windows

πŸš€ Quick Start

Basic Usage

# Compress to 25MB
quantpdf input.pdf output.pdf --size 25

# Compress to 10MB with 150 DPI
quantpdf input.pdf output.pdf --size 10 --dpi 150

# Compress to grayscale
quantpdf input.pdf output.pdf --size 20 --mode grayscale

Advanced Usage

# Maximum quality with 3 optimization passes
quantpdf input.pdf output.pdf --size 25 --dpi 300 --max-passes 3

# Black & white for text documents
quantpdf input.pdf output.pdf --size 5 --mode bw --dpi 200

# With progress logging
quantpdf input.pdf output.pdf --size 25 --log compression.log

Command-Line Options

usage: quantpdf [-h] --input INPUT --output OUTPUT --size SIZE
                [--dpi DPI] [--mode {color,grayscale,bw}]
                [--max-passes PASSES] [--log LOG]

Required arguments:
  --input INPUT         Input PDF file path
  --output OUTPUT       Output PDF file path
  --size SIZE           Target size in MB (e.g., 25 for 25MB)

Optional arguments:
  --dpi DPI             DPI for images (100-300, default: 200)
  --mode MODE           Color mode: color, grayscale, bw (default: color)
  --max-passes PASSES   Max optimization passes (1-3, default: 2)
  --log LOG             Log file path for debugging
  -h, --help            Show this help message

πŸ“– Documentation

User Guides

Technical Documentation

πŸ’‘ Examples

Example 1: Job Application

# Compress resume to meet 10MB limit
quantpdf resume_scanned.pdf resume_compressed.pdf --size 10 --dpi 200

Example 2: Batch Processing

# Process all PDFs in a directory
for file in *.pdf; do
  quantpdf "$file" "compressed_$file" --size 25
done

Example 3: Python Integration

import subprocess
import json

def compress_pdf(input_path, output_path, target_mb):
    """Compress PDF with progress tracking"""
    process = subprocess.Popen(
        ['quantpdf', input_path, output_path, '--size', str(target_mb)],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        text=True
    )
    
    for line in process.stdout:
        event = json.loads(line)
        if event['type'] == 'progress':
            print(f"Progress: {event['percent']}%")
        elif event['type'] == 'complete':
            print(f"Done! Final size: {event['finalSizeMb']}MB")
    
    return process.wait()

# Usage
compress_pdf('input.pdf', 'output.pdf', 25)

See more examples in the examples/ directory.

πŸ–₯️ GUI Version

Want a simpler, visual experience?

QuantPDF is also available as a native macOS app with:

  • πŸ–±οΈ Drag-and-drop interface
  • πŸ‘οΈ Real-time preview
  • πŸ“¦ Batch processing queue
  • πŸ’Ύ Custom presets
  • πŸ“Š Compression history
  • πŸ”„ Automatic updates

Download QuantPDF for macOS β†’

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Start for Contributors

# Fork and clone the repo
git clone https://github.com/paradoxie/quantpdf-cli.git
cd quantpdf-cli

# Install development dependencies
pip install -r requirements.txt
pip install pytest black flake8

# Run tests
pytest tests/

# Format code
black quantpdf_cli.py

# Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Built with Pillow for image processing
  • Uses pdf2image for PDF conversion
  • Powered by Poppler for PDF rendering

πŸ“ž Support

⭐ Star History

If you find this project useful, please consider giving it a star! ⭐

Star History Chart


Made with ❀️ by the QuantPDF team

Website β€’ GUI Version β€’ Documentation

About

Target-size PDF compression from the command line. Compress PDFs to an exact target size, 100% locally and privately.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages