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.
- 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.
You can install pdfzip using one of the following methods:
To install pdfzip from PyPI using pip, run the following command:
pip install pdfzipIf you prefer to clone the repository and install manually, follow these steps:
-
Clone the repository:
git clone https://github.com/dev-r4hul/pdfzip.git cd pdfzip -
Install the package:
pip install . -
(Optional) Add the script to your PATH:
Make sure the installation directory is in your system’s PATH, or create a symbolic link to
pdfzipfor easy access.
Ensure that Ghostscript is installed on your system and available in your system's PATH. You can download it from the official Ghostscript website.
pdfzip can be used from the command line to compress individual PDF files or entire directories of PDF files.
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--backupis 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 compression1: 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_BACKUPto 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 (pdforps). The default format ispdf.pdfzip input.pdf --format ps
Compress document.pdf with the default settings and replace the original file:
pdfzip document.pdfCompress document.pdf with high compression for screen display and save as compressed_document.pdf:
pdfzip document.pdf -o compressed_document.pdf -c 4Compress 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 2Backup original files before compressing:
pdfzip /path/to/folder -bCompress report.pdf and open it with the default PDF viewer:
pdfzip report.pdf --openThe script will provide detailed error messages if something goes wrong, such as:
- Invalid input path
- Unsupported file format
- Missing Ghostscript installation
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.