Skip to main content

pdfcompress-cli

PyPI version Python versions GitHub stars License: MIT Zephyrus Labs

A multi-tier interactive and scriptable PDF compression CLI tool by Zephyrus Labs for Linux, macOS, and Windows.

Reduce bulky PDF documents by up to 85% with smart lossless content-stream optimization, identical object deduplication, and intelligent image downsampling.


Features

  • 🚀 Interactive Wizard: Just run pdfcompress with no flags to launch a guided prompt with automatic default naming.
  • 🎛️ Multi-Tier Compression: 3 curated compression presets from gentle lossless stream optimization to aggressive size reduction.
  • 🖼️ Image Resampling & JPEG Compression: Optimizes embedded images, normalizes color spaces (RGB/RGBA/CMYK), and applies high-quality Lanczos resampling.
  • ⚡ Zero External Binary Dependencies: Pure Python built on pypdf and Pillow—no ghostscript or qpdf system binaries needed!
  • 🔗 Smart Path Handling: Seamlessly accepts shell-escaped paths with spaces (\ ), drag-and-dropped files, and tilde (~) home paths.
  • 📦 Python Library API: Import compress_pdf directly into your own Python applications.
  • 📊 Real-Time Progress & Statistics: Single-line dynamic page counter with percentage and exact byte/percentage savings report.

Installation

Install directly via pip:

pip install pdfcompress-cli

Quick Start

1. Interactive Mode

Run the command without any arguments:

pdfcompress

The interactive wizard will prompt you for:

  1. Input PDF file path (supports drag-and-drop from file managers)
  2. Desired compression level
  3. Output destination (with automatic default naming)

2. Command Line Usage

Compress a PDF using Medium compression (Level 2, default):

pdfcompress document.pdf
# Creates document_compressed_level2.pdf

Specify a custom compression level and output destination:

pdfcompress report.pdf -l 3 -o report_small.pdf

Force overwrite of existing output:

pdfcompress report.pdf -l 2 -o report_small.pdf -f

Compression Tiers

Tier Name Target Savings Technique Ideal For
1 Light ~10–20% Lossless stream compression & object deduplication; retains images 100% untouched Official documents, legal filings, text/vector PDFs
2 Medium (Default) ~40–60% Stream compression + images scaled to max 1600px @ 75% quality Scanned books, email attachments, web uploads
3 Aggressive ~70–85% Stream compression + images scaled to max 1000px @ 40% quality Maximum storage conservation, mobile bandwidth, quick previews

Advanced Image Fine-Tuning

You can override preset defaults with custom image quality and dimension flags:

# Custom 80% JPEG quality and max 1200px dimension
pdfcompress document.pdf -q 80 -d 1200 -o custom.pdf

CLI Options Reference

usage: pdfcompress [-h] [-l {1,2,3}] [-o OUTPUT] [-q QUALITY] [-d MAX_DIM] [-f]
                   [--keep-metadata] [-s] [-v]
                   [input]

Multi-tier PDF Compression CLI Tool

positional arguments:
  input                 Path to input PDF file

options:
  -h, --help            show this help message and exit
  -l, --level {1,2,3}   Compression tier (1=Light, 2=Medium, 3=Aggressive)
  -o, --output OUTPUT   Path for compressed output PDF
  -q, --quality QUALITY Custom JPEG quality (1-100), overrides tier default
  -d, --max-dim MAX_DIM Custom maximum image dimension in px, overrides tier default
  -f, --force           Force overwrite of output file if it exists
  --keep-metadata       Retain original document metadata (by default stripped for size)
  -s, --quiet           Quiet mode; suppress progress information
  -v, --version         show program's version number and exit

Python API Usage

You can also use pdfcompress-cli directly in your Python applications:

from pdf_compressor import compress_pdf, format_size

result = compress_pdf(
    input_path="input.pdf",
    output_path="output.pdf",
    level=2,  # 1=Light, 2=Medium, 3=Aggressive
    strip_metadata=True
)

print(f"Original size:   {format_size(result['orig_mb'])}")
print(f"Compressed size: {format_size(result['final_mb'])}")
print(f"Space saved:     {result['saved_pct']:.1f}%")

Developed & Maintained by Zephyrus Labs

Built and maintained by Zephyrus Labs.

If you find this tool helpful, please give it a ⭐️ on GitHub!


Acknowledgements & Attributions

This tool builds upon and credits the exceptional work of open-source projects:

  • pypdf: Pure Python PDF library used for low-level PDF parsing, stream compression (compress_content_streams), and object deduplication (compress_identical_objects). Licensed under BSD-3-Clause.
  • Pillow: The friendly PIL fork used for image format decoding, Lanczos resampling, and JPEG optimization. Licensed under HPND.

License

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


Lead Developer: Shubham Sharma (@uchiha-fire)

Metadata

Release files for pdfcompress-cli 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdfcompress-cli 0.1.2
File Size Uploaded Provenance
pdfcompress_cli-0.1.2.tar.gz 14.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pdfcompress-cli 0.1.2
File Interpreter ABI Platform
pdfcompress_cli-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / pdfcompress_cli-0.1.2.tar.gz

Download URL pdfcompress_cli-0.1.2.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d269f7dedb720230e53ea4aeef0a3490330ed3ebcc6c1f28443ff37e4d64af1a
BLAKE2b-256 checksum
How to use checksums
c7e922dae901bd4012ad390e0486218acd9dd0da5bb18f8969325d3ae26a6886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / pdfcompress_cli-0.1.2-py3-none-any.whl

Download URL pdfcompress_cli-0.1.2-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72312fdd18bd69fe42bbe380335576ebfd75b461a01549e749c65b5b2fb58050
BLAKE2b-256 checksum
How to use checksums
afaf339ede0ea55ce3059b6560968d8db8e17a4fd9da0ba9084b40eed56b28bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for pdfcompress-cli 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page