How to Resize a PDF in Python
Due to their versatile but static nature, PDFs are often utilized by businesses to share information with clients and customers. Many of these documents begin in another format, such as PPTX or DOCX, and are converted to PDF for increased compatibility and security. In Europe and much of the world, the standard PDF size is A4 (210mm x 297mm), and in the US it’s Letter size (8.5in x 11in). If you need to print a PDF in a size other than standard, the following API will help you resize your PDF to meet your requirements.

Our first step is to install the client software:
pip install cloudmersive-convert-api-client
Then, we can add the imports and call the function with the following code:
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.
paper_size = 'paper_size_example' # str | The desired paper size for the resized PDF document. Size ranges from A7 (smallest) to A0 (largest).try:
# Change PDF Document's Paper Size
api_response = api_instance.edit_pdf_resize(input_file, paper_size)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditPdfApi->edit_pdf_resize: %s\n" % e)
This tool will allow you to automatically set parameters for PDF printing size when appropriate. To retrieve your personal API key, head to the Cloudmersive website to register for a free account and gain access to 800 API calls/month.