Python 3 ILovePDF API Script to Compress PDF Document Using pdf-compressor Command Line Library Full Project For Beginners

 

 

The code in ilovepdf.py was inspired by Andrea Bruschi’s pylovepdf.

Command line PDF compression powered by the free iLovePDF API.

 

About

 

CLI + Python API for batch compressing PDFs

 

 

Installation

 

pip install pdf-compressor

Usage

 

Tell pdf-compressor your iLovePDF API key (if you haven’t yet, get one by signing up at https://developer.ilovepdf.com/signup):

pdf-compressor --set-api-key project_public_7c854a9db0...

Then start compressing!

pdf-compressor **/*.pdf

Options

 

pdf-compressor has the following flags:

 

  • -i/--inplace (optional, default: False): Whether to compress PDFs in place.
  • -s/--suffix (optional, default: '-compressed'): String to append to the filename of compressed PDFs. Mutually exclusive with --inplace.
  • --cl/--compression-level (optional, default: 'recommended'): How hard to squeeze the file size. One of ("low", "recommended", "extreme")'extreme' noticeably degrades quality of embedded bitmap images.
  • --set-api-key (optional): Set the public key needed to authenticate with the iLovePDF API. You only need to do this once to start using.
  • --report-quota (optional): Report the number of remaining file operations in the current billing cycle for the stored iLovePDF API key.
  • --debug (optional, default: False): When true, iLovePDF won’t process the request but only reports the parameters that would have been sent to the server.
  • -v/--version (optional): Get the version number of pdf-compressor.

Leave a Reply