Skip to content

Prachi9306/PDF_Compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF Compressor Project

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.

Features

  • 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.

Requirements

  • Python 3.6+
  • Libraries: Install via pip install -r requirements.txt
  • Ghostscript: Required for advanced compression. Install Ghostscript and ensure gs is in your PATH (or gswin64c.exe on Windows). Without it, only PyMuPDF method will work.

Installation

  1. Clone the repository: git clone <repo-url>
  2. Install dependencies: pip install -r requirements.txt
  3. Install Ghostscript.

Usage

CLI

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

GUI

Run python gui.py to launch the graphical interface (using Tkinter). Note: Currently uses PyMuPDF; update gui.py if needed for Ghostscript.

Web App

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.

Testing

Run pytest in the project root to execute unit tests.

How It Works

  • 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).

Troubleshooting

  • 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.

Limitations

  • Ghostscript requires external installation.
  • Handles basic PDFs; may not work with encrypted or very complex files.
  • Web app uses temporary files; ensure disk space.

⚠️ License & Usage Notice

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages