Reduce the File Size of a PDF in Python
1 min readDec 1, 2020
Large PDF files are a regular part of business operations but can take a long time to process and load between programs and computers. The following API will allow you to reduce the file sizes of a PDF document by optimizing its content.
You can use this API by running this command to install the SDK:
pip install cloudmersive-convert-api-client
Then, you can call the function:
from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'# create an instance of the API class
api_instance = cloudmersive_convert_api_client.EditPdfApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.try:
# Reduce the file size and optimize a PDF
api_response = api_instance.edit_pdf_reduce_file_size(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditPdfApi->edit_pdf_reduce_file_size: %s\n" % e)
You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.