Convert a PDF to PDF/A in Python

Cloudmersive
2 min readDec 1, 2020

--

While PDF is now a household name for saving and sharing document files, it is not always fully compatible with different operating systems. To ensure that your documents always look the way that they are meant to be formatted, the following API will convert PDF files to PDF/A, which is a universal, standardized version of the PDF file type.

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.
conformance_level = 'conformance_level_example' # str | Optional: Select the conformance level for PDF/A - specify '1b' for PDF/A-1b or specify '2b' for PDF/A-2b; default is PDF/A-1b (optional)
try:
# Convert a PDF file to PDF/A
api_response = api_instance.edit_pdf_convert_to_pdf_a(input_file, conformance_level=conformance_level)
pprint(api_response)
except ApiException as e:
print("Exception when calling EditPdfApi->edit_pdf_convert_to_pdf_a: %s\n" % e)

You also have the option to specify the conformance level for your PDF/A document. Specify “1b” for PDF/A-1b or “2b” for PDF/A-2b. The default is PDF/A-1b. 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.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

Responses (1)