Convert PDF to Word in Python

Cloudmersive
1 min readMar 11, 2024

--

Converting PDF to Word with a free API saves time. Using ready-to-run Python code examples, we can be done in minutes.

To begin, let’s install the client SDK. We can run this command to install using pip install:

pip install cloudmersive-convert-api-client

Next, let’s focus on authorizing our API calls. We just need a free Cloudmersive API key, which will allow us to make up to 800 API calls per month with no commitments.

Now let’s copy in the imports and call the function. We can use our PDF file path in our request:

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.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.

try:
# Convert PDF to Word DOCX Document
api_response = api_instance.convert_document_pdf_to_docx(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ConvertDocumentApi->convert_document_pdf_to_docx: %s\n" % e)

All done — that’s all the code we’ll need!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet