As a C# developer, you can easily render DOC or DOCX files to HTML pages programmatically in your .NET applications on the cloud. It can be useful in sharing your Word documents as responsive HTML pages with the relevant stakeholders. In this article, you will learn how to view Word documents as HTML pages using a REST API in C#.
- Word to HTML Viewer REST API and .NET SDK
- View Word as HTML Pages using a REST API in C#
- Render Word to HTML Pages with Rendering Options using C#
- Word to HTML Rendering with Watermark using C#
Word to HTML Viewer REST API and .NET SDK
For rendering DOC or DOCX files to HTML, I will be using the .NET SDK of GroupDocs.Viewer Cloud API. It allows you to programmatically render and view all sorts of popular document and image file formats such as Word, Excel, PDF, PowerPoint, Visio, Project, Outlook, JPG, PNG, etc.
You can install GroupDocs.Viewer Cloud into your Visual Studio project from the NuGet Package Manager or install it using the following command in the Package Manager console:
Install-Package GroupDocs.Viewer-Cloud
Please get your Client ID and Secret from the dashboard before you start following the steps and available code examples. Once you have your client ID and Secret, add in the code as shown below:
View Word Documents as HTML Pages using a REST API in C#
You can view Word documents as HTML pages on the cloud by following the simple steps mentioned below:
- Upload the DOCX file to the cloud
- Render Word to HTML using C#
- Download the rendered HTML pages
Upload the Document
Firstly, upload the DOCX file to the cloud using the code example given below:
As a result, the uploaded DOCX file will be available in the files section of your dashboard.
Render Word to HTML Pages using C#
You can render your Word documents to HTML pages programmatically by following the steps given below:
- Create an instance of the ViewAPI
- Create an instance of the FileInfo
- Provide the input file path
- Create an instance of the ViewOptions
- Assign FileInfo to the ViewOptions
- Set the ViewFormat as “HTML”
- Create a view request by calling the CreateViewRequest method with ViewOptions
- Get a response by calling the CreateView() method with CreateViewRequest
The following code sample shows how to render a Word document to HTML pages using a REST API in C#.
Download the Rendered HTML Pages
The above code sample will save the rendered HTML pages on the cloud. You can download them using the following code sample:
Render Word to HTML Pages with Rendering Options using C#
You can use specific rendering options to render Word documents to HTML pages programmatically by following the steps given below:
- Create an instance of the ViewAPI
- Create an instance of the FileInfo
- Provide the input file path
- Create an instance of the ViewOptions
- Assign FileInfo to the ViewOptions
- Set the ViewFormat as “HTML”
- Create an instance of the RenderOptions
- Set various rendering options such as PagesToRender, RenderComments, etc.
- Create a view request by calling the CreateViewRequest method with ViewOptions
- Get a response by calling the CreateView() method with CreateViewRequest
The following code sample shows how to render a Word document to HTML pages with rendering options using a REST API in C#.
Word to HTML Rendering with Watermark using C#
You can add a watermark text while rendering Word documents to HTML programmatically by following the steps given below:
- Create an instance of the ViewAPI
- Create an instance of the FileInfo
- Provide the input file path
- Create an instance of the ViewOptions
- Assign FileInfo to the ViewOptions
- Set the ViewFormat as “HTML”
- Define Watermark view option
- Set watermark text, size, color, and position
- Create a view request by calling the CreateViewRequest method with ViewOptions
- Get a response by calling the CreateView() method with CreateViewRequest
The following code sample shows how to add a watermark text to rendered HTML pages using a REST API in C#.
Try Online
Please try the following free online Word rendering tool, which is developed using the above API. https://products.groupdocs.app/viewer/docx
Conclusion
In this article, you have learned how to view Word documents as HTML pages on the cloud. You have also learned how to render Word to HTML with rendering options in C#. Moreover, you have learned how to add a text watermark to rendered HTML pages programmatically using C#. Furthermore, you have learned how to programmatically upload a DOCX file to the cloud and then download the rendered HTML files from the cloud. You can learn more about GroupDocs.Viewer Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.