This is a simple PDF compressor tool built in Python. It reduces PDF file sizes by compressing images and optimizing content. It supports a command-line interface (CLI), a graphical user interface (GUI), and a web-based interface for easy file uploads.
- Compress PDFs by reducing image quality, subsetting fonts, and removing duplicates (PyMuPDF method).
- Advanced compression using Ghostscript for better results on mixed image+text PDFs.
- CLI for batch or scripted use.
- GUI for user-friendly interaction.
- Web app with PDF upload, method selection (PyMuPDF or Ghostscript), quality/level selection, and download of compressed files.
- Basic unit tests.
- Python 3.6+
- Libraries: Install via
pip install -r requirements.txt - Ghostscript: Required for advanced compression. Install Ghostscript and ensure
gsis in your PATH (orgswin64c.exeon Windows). Without it, only PyMuPDF method will work.
- Clone the repository:
git clone <repo-url> - Install dependencies:
pip install -r requirements.txt - Install Ghostscript.
Run python main.py --help for options.
Example:
- PyMuPDF:
python main.py input.pdf output.pdf --quality 50 - Ghostscript:
python main.py input.pdf output.pdf --method ghostscript --level ebook
Run python gui.py to launch the graphical interface (using Tkinter). Note: Currently uses PyMuPDF; update gui.py if needed for Ghostscript.
Run streamlit run streamlit_app.py to launch the web-based interface in your browser. Upload a PDF, select method (PyMuPDF or Ghostscript), adjust settings, compress, and download the result. For PDFs with images and text, start with Ghostscript.
Run pytest in the project root to execute unit tests.
compressor.py: Core logic for compression using PyMuPDF/Pillow or Ghostscript.main.py: CLI entry point.gui.py: GUI using Tkinter (PyMuPDF only).streamlit_app.py: Web app using Streamlit for file upload and compression (supports both methods).
- If file expands with PyMuPDF: Lower quality (e.g., 30-50) or switch to Ghostscript—it handles mixed content better.
- Ghostscript not found: Ensure it's installed and in PATH. On Windows, use 'gswin64c' if needed (update compressor.py accordingly).
- For PDFs with few/small images: Reduction may be minimal; Ghostscript's 'screen' level is aggressive.
- Ghostscript requires external installation.
- Handles basic PDFs; may not work with encrypted or very complex files.
- Web app uses temporary files; ensure disk space.
This project is created for learning and demonstration purposes.
You are NOT allowed to: ❌ Copy the code ❌ Reuse the project ❌ Submit it as your own ❌ Use it commercially
Permission is required from the author for any usage.
© Prachi Saini – All Rights Reserved