How to Convert Word DOC (97–03) Document to PDF in Python

If you have had to deal with outdated file formats, then you know the special kind of irritation they bring with them. Today, I am here to demonstrate a simple method for dealing with the problem once and for all. We are going to use Python to convert out of date Microsoft Word DOC files into PDFs.

Let’s begin with installation of our API client, like so.

pip install cloudmersive-convert-api-client

Now we are going to call our function convert_document_doc_to_pdf. As you will notice in the following example, this will require an API instance to be created an API key. This is easy and free.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.ConvertDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Convert Word DOC (97-03) Document to PDFapi_response = api_instance.convert_document_doc_to_pdf(input_file)pprint(api_response)except ApiException as e:print("Exception when calling ConvertDocumentApi->convert_document_doc_to_pdf: %s\n" % e)

And that’s it! Kiss those annoying outdated files goodbye! Within this library, there are other functions for performing the same process on PPT and XLS files, plus almost 200 others besides!

Image for post

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store