Linearize a PDF in Python

1 min readDec 1, 2020

Downloading large documents can be time consuming and puts a pause to your productivity as a result. To combat this, the following API will linearize the contents of a PDF file to optimize it for streaming download. This means that you can view the document as it is loading, cutting your overall time spent working with the file and boosting your efficiency.

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 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.
# Linearize and optimize a PDF for streaming download
api_response = api_instance.edit_pdf_linearize(input_file)
except ApiException as e:
print("Exception when calling EditPdfApi->edit_pdf_linearize: %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.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.