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
- Installation and configuration
- Word to PDF in Python
- The cURL approach for conversion
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
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.
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 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 "https://api.aspose.cloud/connect/token" \ -X POST \ -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"
curl -X GET "https://api.aspose.cloud/v4.0/words/GetStyles.doc?format=pdf&outPath=Resultant.pdf" \ -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.
We also recommend you visit the following links for related information on other features being offered by Cloud APIs