Convert Word to PDF in Python. Save DOC to PDF using Python

doc to pdf in python

Python is among the popular programming languages and in this article, we are going to discuss very simple steps on how to convert Word to PDF in Python application. The whole conversion is performed in the Cloud without using MS Office automation or any other software installed.

Word Processing API

Aspose.Words Cloud is a REST-based API offering the capabilities to read, create, edit, merge, split as well as convert, render and perform a wide variety of other operations on Word documents in the Cloud. It allows you to work with a complete set of Word document components, such as main text, paragraphs, headers, footers, tables, sections, comments, drawing objects, fonts, hyperlinks, math objects, watermarks, and much more. Owing to its REST API architecture, the API can be accessed on any platform. In order to further facilitate our customers, we have specifically created individual programming SDKs, so that our users can take benefit of all these features within the programming language of their choice. In this article, we are further going to discuss Aspose.Words Cloud SDK for Python.

Installation and configuration

The first step in using the Cloud SDK is its installation. The SDK is available for download on PIP and GitHub. Please run the following command to perform the installation from pip.

pip install aspose-words-cloud

In case you are using PyCharm IDE for development purposes, simply search asposewordscloud on the Python Interpreter window under PyCharm -> Preferences… section.

Aspose.Words Cloud Python

Cloud subscription

Data privacy and integrity have integral importance at Aspose. Therefore, we have designed our Cloud APIs to be only accessible to authorized customers. Please note that we provide a free online subscription to our Cloud services and under a free subscription plan, you can perform up to 150 document processing operations. Once you are satisfied with our services, you may consider opting for further plan purchasing, which can be as low as $0.005 / API call.

In order to subscribe, please visit Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Word to PDF in Python

The conversion of MS Word files (DOC, DOCX, etc) into a PDF format can be accomplished by following the steps given below.

  • The first step is to create an ApiClient object which takes Client ID and Client Secret details as arguments
  • Secondly, initialize an instance of WordsApi object which takes ApiClient object as an argument
  • Thridly, call the upload_file(…) method of WordsApi class to upload file to cloud storage
  • The next step is to create ConvertDocumentRequest instance which takes input file name, output file format and resultant file name as arguments
  • Finally, call the convert_document(…) method to perform the conversion operation

The cURL approach for conversion

The cURL commands are one of the smartest approaches to access REST APIs through command prompt. So irrespective of any platform, perform same operations within command line terminal. Since Aspose.Words Cloud is developed on REST Architecture, so it can easily be accessed via the cURL commands. However, in order to use the cURL commands, the first step is to generate JSON Web Token (JWT) which is used to access the APIs through cURL commands.

Please login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details. For more information, please visit How to Obtain JWT token using a Client ID and Client Secret key.

Use the following command to generate a JWT token based on provided Client ID and Client Secret.

curl -v "" \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token has been generated, access GetDocumentWithFormat API to perform DOC to PDF conversion.

curl -X GET "" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"


In this article, we have discussed some exciting features of Aspose.Words Cloud API for converting word to pdf in python. You may perform the conversion of MS Word documents including but not limited to (DOC, DOCX, etc) formats. Furthermore, please note that you may also convert Word documents to other formats including PDF, XPS, SVG, PCL, JPEG, and much more. For more information, please visit the Overview section.

In case you encounter any issues while using our cloud services, please contact us via the Free product support forum.

Related Links

We also recommend you visit the following links for related information on other features being offered by Cloud APIs