Display Word document in web after converting Word to HTML using Python SDK

Convert Word to HTML

Convert Word to HTML | Word to HTML Conversion with Python SDK

This article is going to explain the steps to convert Word to HTML using Python SDK. We know that Word documents are widely used for official and personal information sharing. However, the challenge comes when we need to view or display the document in a web browser. So a smart solution is to convert Word documents to HTML format.

Word to HTML Conversion API

Aspose.Words Cloud is capable of loading MS Word, OpenOffice, or WordProcessingML documents. It enables you to manipulate at individual element level or transform these files to Supported File Formats. Now in order to utilize the document processing features in the Python application, we need to use Aspose.Words Cloud SDK for Python. So in order to use the SDK, the first step is the installation which is available for download at PIP and GitHub. Execute the following command on the command line terminal to install the SDK:

pip install aspose-words-cloud

The next step is to create a free account by visiting Aspose.Cloud dashboard, so that you can manage your documents in cloud storage.

Convert Word to HTML using Python

Please follow the instructions given below to load the Word document from the local drive and upload it to cloud storage. Then we will initialize the routine to convert DOC file to HTML format and save the output in the same cloud storage.

  • First of all, create an instance of WordsApi using client credentials
  • Secondly, word document from local drive and upload to Cloud storage using upload_file(…) method
  • Now create an instance of GetDocumentWithFormatRequest defining input Word file and resultant HTML document
  • Finally, call the method get_document_with_format(…) to initiate the conversion process

The sample word document used in the above example can be downloaded from test_multi_pages.docx.

Word to HTML Conversion using cURL Command

The cURL commands can also be used to convert word documents to HTML format. However before we initiate the conversion process, we need to create a JWT access token based on personal client credentials. So please create the JWT token by executing the following command.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bbf94a2c-6d7e-4020-b4d2-b9809741374e&client_secret=1c9379bb7d701c26cc87e741a29987bb" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token is generated, we need to execute the following command to upload a sample word document to cloud storage:

curl -v -X PUT "https://api.aspose.cloud/v4.0/words/storage/file/input.docx" \
-H  "accept: application/json" \
-H  "Authorization: Bearer <JWT Token>" \
-H  "Content-Type: multipart/form-data" \
-d {"fileContent":{c:\Users\nayyer\Downloads\test_doc.docx}}

Now please execute the following command to convert the word document from cloud storage to HTML format and save the resultant HTML to the same cloud storage.

curl -v -X GET "https://api.aspose.cloud/v4.0/words/test_multi_pages.docx?format=HTML&outPath=Resultant.html" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"

Conclusion

In this article, we have learned about the steps to perform Word to HTML using Python SDK. Similarly, we have also explored the option to perform DOC to HTML, DOCX to HTML conversion using cURL commands. The complete conversion process is so simple and straightforward that you only need to focus on your business requirements and forget about the internal document conversion complexities. The API manages all the inter-document conversion routines and returns the resultant content. We suggest you explore the Programmers Guide to learn about other capabilities being offered by the SDK. Furthermore, the complete source code of cloud SDK is available for download over GitHub and you can download and update it as per your requirements.

We recommend you to visit the following articles to learn about: