https://github.com/janosh/pdf-compressor
CLI + Python API for batch compressing PDFs
https://github.com/janosh/pdf-compressor
cli compression ilovepdf-api pdf
Last synced: 3 months ago
JSON representation
CLI + Python API for batch compressing PDFs
- Host: GitHub
- URL: https://github.com/janosh/pdf-compressor
- Owner: janosh
- License: mit
- Created: 2021-06-14T13:35:10.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T14:21:03.000Z (3 months ago)
- Last Synced: 2025-04-02T06:51:34.613Z (3 months ago)
- Topics: cli, compression, ilovepdf-api, pdf
- Language: Python
- Homepage: https://pypi.org/project/pdf-compressor
- Size: 136 KB
- Stars: 31
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
![]()
[](https://github.com/janosh/pdf-compressor/actions)
[](https://results.pre-commit.ci/latest/github/janosh/pdf-compressor/main)
[](https://pypi.org/project/pdf-compressor)
[](https://python.org/downloads)
[](https://pypistats.org/packages/pdf-compressor)Command line PDF compression powered by the free [iLovePDF API](https://developer.ilovepdf.com).
**Why?** iLovePDF delivers the best PDF compression I've seen but their web UI doesn't support automation and can be cumbersome when dealing with many files.
## Installation
```sh
pip install pdf-compressor
```## Usage
First, tell `pdf-compressor` your iLovePDF API key (if you haven't yet, get one by signing up at ):
```sh
pdf-compressor --set-api-key project_public_7c854a9db0...
```Then start compressing!
```sh
pdf-compressor **/*.pdf
```## Options
| Flags | Default | Description |
| -------------------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-i/--inplace` | `False` | Whether to compress PDFs in place. |
| `-s/--suffix` | `'-compressed'` | String to append to the filename of compressed PDFs. Mutually exclusive with `--inplace`. |
| `--cl/--compression-level` | `'recommended'` | How hard to squeeze the file size. One of `'low'`, `'recommended'`, `'extreme'`. `'extreme'` noticeably degrades quality of embedded bitmap images. |
| `--set-api-key` | | Set the public key needed to authenticate with the iLovePDF API. You only need to do this once to start using. |
| `--report-quota` | | Report the number of remaining file operations in the current billing cycle for the stored iLovePDF API key. |
| `--debug` | `False` | When true, iLovePDF won't process the request but only reports the parameters that would have been sent to the server. |
| `--verbose` | `False` | When true, progress will be reported while tasks are running. |
| `-v/--version` | | Get the version number of `pdf-compressor`. |
| `--on-no-files` | `'ignore'` | What to do when no input PDFs received. One of `'ignore'` or `'error'`, former exits 0, latter raises `ValueError`. Can be useful when using `pdf-compressor` in shell scripts. |
| `--on-bad-files` | `'error'` | How to behave when receiving input files that don't appear to be PDFs. One of `'error'`, `'warn'`, `'ignore'`. Error type will be `ValueError`. Code used to check if something is PDF: `filepath.lower().endswith(".pdf")` |