Skip to content

Commit

Permalink
Updated rendering web documents
Browse files Browse the repository at this point in the history
  • Loading branch information
muqarrab-aspose committed Mar 14, 2024
1 parent f777fa5 commit f0d85c1
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 130 deletions.
4 changes: 3 additions & 1 deletion content/english/net/rendering-web-documents/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ url: /net/rendering-web-documents/

## Rendering Web Documents Tutorials
### [Render CHM Files](./render-chm/)
### [Render HTML with User-Defined Margins](./render-html-margins/)
Learn how to render CHM files in .NET using GroupDocs.Viewer. Convert CHM to HTML, JPG, PNG, and PDF formats effortlessly.
### [Render HTML with User-Defined Margins](./render-html-margins/)
Learn how to render HTML with custom margins in .NET using GroupDocs.Viewer. Enhance document presentation effortlessly.
179 changes: 121 additions & 58 deletions content/english/net/rendering-web-documents/render-chm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,139 @@
title: Render CHM Files
linktitle: Render CHM Files
second_title: GroupDocs.Viewer .NET API
description:
description: Learn how to render CHM files in .NET using GroupDocs.Viewer. Convert CHM to HTML, JPG, PNG, and PDF formats effortlessly.
type: docs
weight: 10
url: /net/rendering-web-documents/render-chm/
---
## Introduction
In this tutorial, we'll explore how to render CHM (Compiled HTML Help) files using GroupDocs.Viewer for .NET. GroupDocs.Viewer for .NET is a powerful document rendering API that allows developers to display over 170 document types within their .NET applications without requiring any external software installations.

## Prerequisites

Before we dive into rendering CHM files, ensure you have the following prerequisites:

### Installing GroupDocs.Viewer for .NET

To get started, you need to install GroupDocs.Viewer for .NET. You can download the library from the [GroupDocs website](https://releases.groupdocs.com/viewer/net/) or install it via NuGet Package Manager by running the following command in the Package Manager Console:

```bash
Install-Package GroupDocs.Viewer
```

## Importing Namespaces

Make sure to import the necessary namespaces into your project:

## Complete Source Code
```csharp
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using GroupDocs.Viewer.Options;
```

Now let's break down the rendering process into multiple steps:

## Step 1: Define Output Directory

Define the directory where you want the rendered files to be saved:

```csharp
string outputDirectory = "Your Document Directory";
```

## Step 2: Render to HTML

To render CHM files to HTML, use the following code snippet:

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Rendering.RenderingOptionsByDocumentType.RenderingWebDocuments
```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.html");

using (Viewer viewer = new Viewer("Your_CHM_File_Path"))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
options.RenderToSinglePage = true; // Set to true to convert all CHM content to a single page
viewer.View(options); // Convert all pages
}
```

## Step 3: Render to JPG

To render CHM files to JPG images, use the following code snippet:

```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.jpg");

using (Viewer viewer = new Viewer("Your_CHM_File_Path"))
{
/// <summary>
/// This example demonstrates how to render CHM document into HTML, JPG, PNG, PDF.
/// </summary>
public class RenderingChmFiles
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.html");

// TO HTML
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFilePathFormat);
options.RenderToSinglePage = true; // Enable it if you want to convert all CHM content to single page
//viewer.View(options,1,2,3); // Convert only 1,2,3 pages
viewer.View(options); // Convert all pages
}

// TO JPG
pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.jpg");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
{
JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);

viewer.View(options,1,2,3); // Convert only 1,2,3 pages
//viewer.View(options); // Convert all pages
}

// TO PNG
pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.png");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
{
PngViewOptions options = new PngViewOptions(pageFilePathFormat);

viewer.View(options,1,2,3); // Convert only 1,2,3 pages
//viewer.View(options); // Convert all pages
}

// TO PDF
pageFilePathFormat = Path.Combine(outputDirectory, "chm_result.pdf");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_CHM))
{
PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);

viewer.View(options); // Convert all pages
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}
}
JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);

viewer.View(options, 1, 2, 3); // Convert only pages 1, 2, 3
}
```

## Step 4: Render to PNG

To render CHM files to PNG images, use the following code snippet:

```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result_{0}.png");

using (Viewer viewer = new Viewer("Your_CHM_File_Path"))
{
PngViewOptions options = new PngViewOptions(pageFilePathFormat);

viewer.View(options, 1, 2, 3); // Convert only pages 1, 2, 3
}
```

## Step 5: Render to PDF

To render CHM files to a PDF document, use the following code snippet:

```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "chm_result.pdf");

using (Viewer viewer = new Viewer("Your_CHM_File_Path"))
{
PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);

viewer.View(options); // Convert all pages
}
```

## Step 6: Check Output

Once the rendering process is complete, check the specified output directory for the rendered files:

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

## Conclusion

Rendering CHM files using GroupDocs.Viewer for .NET is a straightforward process. By following the steps outlined in this tutorial, you can efficiently convert CHM documents into various formats such as HTML, images (JPG, PNG), and PDF within your .NET applications.

## FAQ's

### Q1: Can GroupDocs.Viewer render other document formats apart from CHM?

A1: Yes, GroupDocs.Viewer supports rendering over 170 document formats including PDF, DOCX, XLSX, PPTX, and more.

### Q2: Is GroupDocs.Viewer compatible with .NET Core?

A2: Yes, GroupDocs.Viewer supports .NET Core in addition to the traditional .NET Framework.

### Q3: Can I customize the rendering options for different output formats?

A3: Yes, GroupDocs.Viewer provides various options for customizing the rendering process, such as specifying page numbers, setting image quality, and configuring output paths.

### Q4: Does GroupDocs.Viewer require any external dependencies for rendering documents?

A4: No, GroupDocs.Viewer is a standalone library and does not require any external dependencies or third-party software installations.

### Q5: Is there a free trial available for GroupDocs.Viewer?

A5: Yes, you can avail of a free trial of GroupDocs.Viewer by visiting the [website](https://releases.groupdocs.com/).
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,86 @@
title: Render HTML with User-Defined Margins
linktitle: Render HTML with User-Defined Margins
second_title: GroupDocs.Viewer .NET API
description:
description: Learn how to render HTML with custom margins in .NET using GroupDocs.Viewer. Enhance document presentation effortlessly.
type: docs
weight: 11
url: /net/rendering-web-documents/render-html-margins/
---
## Introduction
In the realm of .NET development, rendering HTML with user-defined margins is a crucial aspect of creating visually appealing documents. Whether it's adjusting margins for a website or configuring print layouts, precise control over margins enhances the overall presentation of content. In this tutorial, we'll delve into utilizing GroupDocs.Viewer for .NET to achieve this functionality seamlessly.
## Prerequisites
Before diving into the tutorial, ensure you have the following prerequisites:
1. GroupDocs.Viewer for .NET: Install GroupDocs.Viewer for .NET library. You can download it from the [website](https://releases.groupdocs.com/viewer/net/).
2. .NET Environment: Have a working environment for .NET development.
3. HTML Document: Prepare an HTML document that you want to render with custom margins.

## Complete Source Code
## Import Namespaces
Before you begin, make sure to import the necessary namespaces:
```csharp
using GroupDocs.Viewer.Options;
using System;
using System.IO;

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Rendering.RenderingOptionsByDocumentType.RenderingWebDocuments
```
## Step 1: Set Output Directory
Define the directory where you want the rendered files to be saved:
```csharp
string outputDirectory = "Your Document Directory";
```
## Step 2: Define Page File Path Format
Set the format for the file paths of rendered pages:
```csharp
string pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins_page_{0}.jpg");
```
## Step 3: Adjust Margins for JPG Rendering
Configure margins for rendering HTML to JPG format:
```csharp
using (Viewer viewer = new Viewer("Path_to_your_HTML_file"))
{
/// <summary>
/// This example demonstrates how to render HTML files with user defined margins.
/// </summary>
public class RenderingHtmlWithUserDefinedMargins
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins_page_{0}.jpg");

/*
You can adjust margins (top,bottom,left,right) of final document by setting following properties in
options.WordProcessingOptions:
LeftMargin
RightMargin
TopMargin
BottomMargin
Default values in points are:
LeftMargin = RightMargin = 5
TopMargin = BottomMargin = 72
*/

// TO JPG
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
{
JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;

viewer.View(options);
}

pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins_page_{0}.png");

// TO PNG
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
{
PngViewOptions options = new PngViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;

viewer.View(options);
}

pageFilePathFormat = Path.Combine(outputDirectory, "html_render_margins.pdf");

// TO PDF
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_HTML))
{
PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;

viewer.View(options);
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}
}
JpgViewOptions options = new JpgViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
```
## Step 4: Adjust Margins for PNG Rendering
Similarly, adjust margins for rendering HTML to PNG format:
```csharp
using (Viewer viewer = new Viewer("Path_to_your_HTML_file"))
{
PngViewOptions options = new PngViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
```
## Step 5: Adjust Margins for PDF Rendering
For PDF rendering, set the margins accordingly:
```csharp
using (Viewer viewer = new Viewer("Path_to_your_HTML_file"))
{
PdfViewOptions options = new PdfViewOptions(pageFilePathFormat);
options.WordProcessingOptions.LeftMargin = 40;
options.WordProcessingOptions.RightMargin = 40;
options.WordProcessingOptions.TopMargin = 40;
options.WordProcessingOptions.BottomMargin = 40;
viewer.View(options);
}
```

## Conclusion
Customizing margins when rendering HTML documents in .NET using GroupDocs.Viewer allows developers to tailor the presentation of content precisely. By following this tutorial, you can effortlessly adjust margins for JPG, PNG, or PDF output formats, enhancing the visual appeal and readability of your documents.
## FAQ's
### Is GroupDocs.Viewer for .NET compatible with different HTML formats?
GroupDocs.Viewer supports a wide range of HTML formats, ensuring compatibility with various HTML documents.
### Can I adjust margins dynamically based on document content?
Yes, you can programmatically adjust margins based on document properties or user preferences.
### Are there any limitations on the margin adjustments?
GroupDocs.Viewer offers flexibility in margin adjustments, allowing customization within reasonable limits.
### Does GroupDocs.Viewer support other output formats apart from JPG, PNG, and PDF?
Yes, GroupDocs.Viewer supports rendering to various formats, including TIFF, SVG, and more.
### How can I seek further assistance or report issues related to GroupDocs.Viewer?
You can visit the GroupDocs.Viewer forum [here](https://forum.groupdocs.com/c/viewer/9) for support and discussions.

0 comments on commit f0d85c1

Please sign in to comment.