Skip to main content

A simple PDF compressor using Ghostscript

Project description

pdfzip

A simple and efficient PDF compressor using Ghostscript. This tool allows you to compress PDF files with various levels of compression, making it ideal for reducing file sizes for storage or sharing.

Features

  • Multiple Compression Levels: Choose from five different levels of compression to suit your needs.
  • Improved Error Handling: Provides detailed error messages to help diagnose issues.
  • Batch Processing: Compress all PDF files in a folder with ease.
  • Cross-Platform Support: Works on Windows, macOS, and Linux.
  • Optional Progress Display: View compression progress and results directly in the console.
  • Different Output Formats: Choose between PDF and PS (PostScript) formats for output files.
  • Backup Options: Automatically create backups of original files if desired.

Installation

You can install pdfzip using one of the following methods:

Option 1: Install via pip

To install pdfzip from PyPI using pip, run the following command:

pip install pdfzip

Option 2: Install via Git Clone

If you prefer to clone the repository and install manually, follow these steps:

  1. Clone the repository:

    git clone https://github.com/dev-r4hul/pdfzip.git
    cd pdfzip
    
  2. Install the package:

    pip install .
    
  3. (Optional) Add the script to your PATH:

    Make sure the installation directory is in your system’s PATH, or create a symbolic link to pdfzip for easy access.

Ghostscript Installation

Ensure that Ghostscript is installed on your system and available in your system's PATH. You can download it from the official Ghostscript website.

Usage

pdfzip can be used from the command line to compress individual PDF files or entire directories of PDF files.

Command-Line Arguments

Here are the available command-line arguments and their descriptions:

  • input (required):
    Path to the input PDF file or directory containing PDF files.

    pdfzip input.pdf
    pdfzip /path/to/pdf/directory
    
  • -o, --out (optional):
    Path to the output PDF file or directory for compressed PDFs. If not specified, the original file will be replaced (unless --backup is used).

    pdfzip input.pdf -o compressed_output.pdf
    pdfzip /path/to/pdf/directory -o /path/to/output/directory
    
  • -c, --compress (optional, default=2):
    Compression level from 0 to 4. Choose the appropriate level based on your needs:

    • 0: Default compression
    • 1: Prepress (high quality, larger size)
    • 2: Printer (good quality, suitable for print)
    • 3: eBook (medium quality, smaller size)
    • 4: Screen (low quality, smallest size)
    pdfzip input.pdf -c 3
    
  • -b, --backup (optional):
    Create a backup of the original PDF file(s) before compression, appending _BACKUP to the filename.

    pdfzip input.pdf -b
    
  • --open (optional, default=False):
    Open the PDF file after compression using the default PDF viewer for your system.

    pdfzip input.pdf --open
    
  • --format (optional, default=pdf):
    Specify the output format (pdf or ps). The default format is pdf.

    pdfzip input.pdf --format ps
    

Examples

Compress a Single PDF File

Compress document.pdf with the default settings and replace the original file:

pdfzip document.pdf

Compress document.pdf with high compression for screen display and save as compressed_document.pdf:

pdfzip document.pdf -o compressed_document.pdf -c 4

Compress Multiple PDF Files in a Folder

Compress all PDFs in a folder with the printer setting and save in a separate output folder:

pdfzip /path/to/folder -o /path/to/output/folder -c 2

Backup original files before compressing:

pdfzip /path/to/folder -b

Open PDF After Compression

Compress report.pdf and open it with the default PDF viewer:

pdfzip report.pdf --open

Error Handling

The script will provide detailed error messages if something goes wrong, such as:

  • Invalid input path
  • Unsupported file format
  • Missing Ghostscript installation

Troubleshooting

If you encounter any issues, ensure that Ghostscript is installed correctly and available in your system's PATH. If you need further assistance, please refer to the Ghostscript documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfzip-0.1.0.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

pdfzip-0.1.0-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page