doc to html

DOC to HTML conversion with C# .NET.

We know that Word documents offer a convenient way to author and format the content, but the HTML format opens up a world of possibilities for content accessibility, versatility, and integration. Therefore, by converting Word documents to HTML is not just about compatibility; it’s about ensuring content is web-friendly, responsive, and easily accessible across various devices and platforms.

In this article, we are going to discuss the details on how we can easily convert Word document (DOC, DOCX) to HTML format using .NET REST API.

REST API for Word to HTML Conversion

The conversion of Word documents to HTML format using GroupDocs.Conversion Cloud SDK for .NET offers a highly convenient and efficient solution for content transformation. The SDK handles all aspects of the conversion process, including preserving document structure, formatting, and styles, ensuring that the resulting HTML maintains the integrity and readability of the original content.

Firstly, we need to install the SDK by searching GroupDocs.Conversion-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.

NuGet\Install-Package GroupDocs.Conversion-Cloud -Version 24.4.0

Secondly, we need to obtain our personalized API credentials(i.e. Client ID and Client Secret). Please follow the instructions specified in this short tutorial explaining the details on how to get the API credentials.

Convert DOC to HTML in C#

In this section, we are going to explore the details on how GroupDocs.Conversion Cloud SDK for .NET provides a convenient and reliable platform for converting Word documents to HTML and empowers you to streamline the content transformation workflows with ease.

  1. Create an instance of Configuration class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
  1. Initialize the ConvertApi where we pass Configuration object as an input argument.
var apiInstance = new ConvertApi(configurations);
  1. Upload the input Word document to the cloud storage.
fileUpload.UploadFile(new UploadFileRequest("input-sample.doc", stream));
  1. Create an instance ConvertSettings where we specify the name of input Word document, resultant format as html and the name for output HTML file as arguments.
var settings = new ConvertSettings{...}
  1. Call the ConvertDocumentRequest API to export the Word document to HTML format and save the resultant HTML to the cloud storage.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
docx to html

Image:- A preview of DOCX to HTML conversion.

DOCX to HTML using cURL Commands

One of the key advantages of using GroupDocs.Conversion Cloud with cURL commands is the simplicity and flexibility it offers. You can easily integrate the conversion process into your workflows or scripts with ease, and automate the DOCX to HTML conversion task efficiently.

The first step in this approach is to generate the JWT access token based on client credentials. Once we have generated the JWT token, we need to execute the following cURL command to convert the Word document to HTML format and save the resultant file to cloud storage.

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{inputFile}\",  \"Format\": \"html\",  \"LoadOptions\": {    \"Format\": \"docx\"  },  \"OutputPath\": \"{resultantHTML}\"}"

Please replace inputFile with the name of input Word document, resultantHTML with the name of resultant HTML file and accessToken with personalized JWT access token.

  • In order to save the resultant HTML to local drive, please try using the following cURL command:
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{inputFile}\",  \"Format\": \"html\",  \"LoadOptions\": {    \"Format\": \"doc\"  }}" \
-o "myResultant.html"

Word to HTML Conversion App

Please don’t forget to try using our lightweight and supper-efficient DOCX to HTML Conversion App. This free App is built on top of GroupDocs.Conversion Cloud APIs and enables you to witness the amazing capabilities of Word document to HTML conversion API.

DOCX to HTML converter

Conclusion

Whether you prefer the simplicity and flexibility of cURL commands or the comprehensive capabilities offered by GroupDocs.Conversion Cloud API directly, the conversion of Word documents (DOC, DOCX etc.) to HTML format becomes a seamless and efficient process. Both approaches provide a reliable solutions for content transformation, ensuring that the resulting HTML maintains the integrity, formatting, and structure of the original document.

We also recommend visiting the following links to learn more about: