Skip to main content

cli tool wrapper for manipulating multiple pdfs file in parallel using ghostscript (compressing, convert to pdfa, etc.)

Project description

gs-batch-pdf

gs-batch-pdf is a command-line tool for batch (parallel) processing PDF files using Ghostscript, applying the same set of gs options to all files specified while taking care of file renaming.

It offers convenient default settings for compression, PDF/A conversion, and you can also apply any custom Ghostscript options.

Features

  • Batch process multiple PDF files
  • Compress PDFs with various quality settings
  • Convert PDFs to PDF/A format[^1]
  • Apply custom Ghostscript options
  • Multi-threaded processing for improved performance
  • Progress tracking with tqdm
  • Automatic file renaming with customizable prefixes and suffixes
  • Option to keep either the smaller file or the new file after processing
  • Cross-platform support (Windows, Linux, macOS)

[^1]: you need to use gs version 10.04.0 or higher for correct PDF/A level 2 or 3 conversion.

Installation

To install gs-batch-pdf, make sure you have Python 3.12+ and pipx[^2] installed, then run:

[^2]:pipx will let you install the package in a virtual environment, but the commands will be available from the command line

pipx install gs-batch-pdf

Note: This tool requires Ghostscript to be installed on your system. Make sure you have Ghostscript installed and accessible from the command line.

Usage

Basic usage:

gs_batch and the its alias gsb will be available from the command line.

gs-batch-pdf [OPTIONS] FILES...

Options:

  • --options TEXT: Arbitrary Ghostscript options and switches.
  • --compress TEXT: Compression quality level (e.g., /screen, /ebook, /printer, /prepress) (default: /ebook).
  • --pdfa INTEGER: PDF/A version (1 for PDF/A-1, 2 for PDF/A-2, 3 for PDF/A-3; default: 2).
  • --prefix TEXT: Prefix to add to the output file name.
  • --suffix TEXT: Suffix to add to the output file name before the extension.
  • --keep_smaller / --keep_new: Keep the smaller file between old and new (default: keep smaller).
  • --force: Allow overwriting the original file.

Examples

  1. Compress multiple PDF files using ebook quality:
gs_batch --compress=/ebook file1.pdf file2.pdf file3.pdf
  1. Convert PDFs to PDF/A-2 format:
gs_batch --pdfa=2 file1.pdf file2.pdf
  1. Compress and Convert PDFs to PDF/A-2 format all pdfs in a folder:
# you can use glob patterns
gs_batch --compress --pdfa=2 *.pdf 
  1. Apply custom Ghostscript options:
gs_batch --options="-dPDFSETTINGS=/screen -dColorImageResolution=72" file.pdf
  1. Add prefix^[you can also specify new folder] and suffix to output files:
gs_batch --prefix="./compressed/" --suffix="_v1" --compress=/screen file*.pdf 

Output

After processing, gs-batch-pdf will display a summary table showing the original size, new size, compression ratio, and which file was kept for each processed PDF. The tool will also attempt to open the output folder in your default file manager.

Requirements

  • Python 3.12+
  • Ghostscript
  • click
  • tqdm
  • showinfm

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Acknowledgements

gs-batch-pdf uses Ghostscript for PDF processing. Ghostscript is released under the GNU Affero General Public License (AGPL).

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

gs_batch_pdf-0.3.1b2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

gs_batch_pdf-0.3.1b2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file gs_batch_pdf-0.3.1b2.tar.gz.

File metadata

  • Download URL: gs_batch_pdf-0.3.1b2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.9.3-76060903-generic

File hashes

Hashes for gs_batch_pdf-0.3.1b2.tar.gz
Algorithm Hash digest
SHA256 c2f9faf1e4433629a5262435f8c54fe1d75feaf6a8f4c180755961b5bef5cac0
MD5 03f4ab7feb7f111d21fe1c72f5dba1bc
BLAKE2b-256 208772a9c5909299f7c15999c586e4dce3f0e6c4fb72313baceea10a92bcd37e

See more details on using hashes here.

File details

Details for the file gs_batch_pdf-0.3.1b2-py3-none-any.whl.

File metadata

  • Download URL: gs_batch_pdf-0.3.1b2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.9.3-76060903-generic

File hashes

Hashes for gs_batch_pdf-0.3.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 342eced9f2b76d91e12c0bf1d9be5c007732af494b2d4148214c2e2ff93282ca
MD5 ebc928d1b3c596e42aa6a29590d1b882
BLAKE2b-256 4462ae99e08a55e2a2cbf0c74738491ad9e11361645f9d00cb115d19f5110720

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