Render Responsive HTML

Introduction

Groupdocs.Viewer for .NET is a powerful library that allows developers to render various document formats into responsive HTML. This tutorial will guide you through the process of rendering responsive HTML using Groupdocs.Viewer for .NET. By the end of this tutorial, you will be able to seamlessly convert documents into HTML that adapts to different screen sizes, ensuring optimal viewing experience across devices.

Prerequisites

Before you begin, ensure that you have the following:

  1. Groupdocs.Viewer for .NET Library: Download and install the library from the website.
  2. Development Environment: Make sure you have a suitable development environment set up for .NET development.
  3. Document Files: Prepare the document files that you want to render into responsive HTML.

Import Namespaces

To start rendering responsive HTML, import the necessary namespaces into your project:

using System;
using System.IO;
using GroupDocs.Viewer.Options;

Let’s break down the rendering process into multiple steps:

Step 1: Set Output Directory

Define the directory where you want the rendered HTML pages to be saved:

string outputDirectory = "Your Document Directory";

Step 2: Define Page File Path Format

Specify the format for naming the HTML files for each page:

string pageFilePathFormat = Path.Combine(outputDirectory, "page_{0}.html");

Step 3: Initialize Viewer Object

Create an instance of the Viewer class and specify the document to be rendered:

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_DOCX))
{
    // Rendering code will go here
}

Step 4: Configure HTML View Options

Set up the HTML view options, including enabling responsive rendering:

HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
options.RenderResponsive = true;

Step 5: Render Document into HTML

Use the View method of the Viewer object to render the document into HTML:

viewer.View(options);

Step 6: Output Success Message

Display a message indicating that the document has been successfully rendered:

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");

Conclusion

In conclusion, Groupdocs.Viewer for .NET provides a seamless solution for rendering documents into responsive HTML. By following the steps outlined in this tutorial, you can effortlessly convert your documents into HTML format that adapts to different screen sizes, ensuring an optimal viewing experience for your users.

FAQ’s

Is Groupdocs.Viewer for .NET compatible with all document formats?

Groupdocs.Viewer for .NET supports a wide range of document formats including DOCX, PDF, PPTX, XLSX, and more.

Can I customize the appearance of the rendered HTML?

Yes, you can customize various rendering options such as page orientation, quality, and watermarking according to your requirements.

Does Groupdocs.Viewer for .NET require a license for commercial use?

Yes, a commercial license is required for using Groupdocs.Viewer for .NET in production environments. You can purchase a license from the website.

Is there a free trial available for Groupdocs.Viewer for .NET?

Yes, you can avail of a free trial of Groupdocs.Viewer for .NET from the website.

Where can I get support for Groupdocs.Viewer for .NET?

You can get support from the Groupdocs.Viewer community forums here.