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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pdfzip-0.1.0.tar.gz.

File metadata

  • Download URL: pdfzip-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pdfzip-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0274f79b9a75ee20e96c8086b50be7bfb478655c70845da6b3daa0c525d7dc7
MD5 ae1a41cadb6e48f544352ad50cf1db44
BLAKE2b-256 a123128a18aa5d2ef0757c62295b1289b39e0bed9dcce476a3977a079b76c2cc

See more details on using hashes here.

File details

Details for the file pdfzip-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pdfzip-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pdfzip-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce443807bc62ce34e36feaf3cb875d8f1de416e1a2b5b8778c1e0fb622e1de0c
MD5 6d177dffb6a72dfd583df957d508355c
BLAKE2b-256 7103485ea7e1718453401e395cd851e0891bc806dd27eebf0b2f360538c40fec

See more details on using hashes here.

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