Skip to content

Commit

Permalink
Updated rendering text file
Browse files Browse the repository at this point in the history
  • Loading branch information
muqarrab-aspose committed Mar 14, 2024
1 parent 9943767 commit 93f46d2
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 67 deletions.
3 changes: 2 additions & 1 deletion content/english/net/rendering-text-files/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ url: /net/rendering-text-files/
---

## Rendering Text Files Tutorials
### [Render Text Files (.txt)](./render-txt/)
### [Render Text Files (.txt)](./render-txt/)
Explore the seamless conversion of text files into multiple formats using GroupDocs.Viewer for .NET. Enhance your document management capabilities effortlessly.
165 changes: 99 additions & 66 deletions content/english/net/rendering-text-files/render-txt/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,116 @@
title: Render Text Files (.txt)
linktitle: Render Text Files (.txt)
second_title: GroupDocs.Viewer .NET API
description:
description: Explore the seamless conversion of text files into multiple formats using GroupDocs.Viewer for .NET. Enhance your document management capabilities effortlessly.
type: docs
weight: 10
url: /net/rendering-text-files/render-txt/
---

## Complete Source Code
## Introduction
In the realm of document management and manipulation, GroupDocs.Viewer for .NET emerges as a powerful tool, offering a plethora of functionalities to render various document formats efficiently. This article delves into the intricacies of utilizing GroupDocs.Viewer for .NET to render text files (.txt) into multiple formats. Whether you aim to convert text files into HTML, JPG, PNG, or PDF, GroupDocs.Viewer equips you with the necessary tools to accomplish these tasks seamlessly.
## Prerequisites
Before delving into the conversion process, ensure you have the following prerequisites in place:
### 1. Installation of GroupDocs.Viewer for .NET
Ensure you have GroupDocs.Viewer for .NET installed in your development environment. You can download the necessary files from the [website](https://releases.groupdocs.com/viewer/net/).
### 2. Basic Familiarity with .NET Framework
Familiarize yourself with the basics of the .NET framework, including how to set up a project and utilize libraries within your codebase.
### 3. Sample Text Files
Prepare sample text files (.txt) that you intend to convert. These files will serve as the input for the conversion process.

## Import Namespaces
Before diving into the conversion process, make sure to import the necessary namespaces into your project. This allows you to access the functionalities provided by GroupDocs.Viewer for .NET seamlessly.
```csharp
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using GroupDocs.Viewer.Options;
string outputDirectory = "Your Document Directory";
```
Let's break down each example into multiple steps to guide you through the conversion process effectively:

namespace GroupDocs.Viewer.Examples.CSharp.AdvancedUsage.Rendering.RenderingOptionsByDocumentType.RenderingTextDocuments
## Step 1: Define HTML Output Path
```csharp
string pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.html");
```
Specify the full path for the HTML output file.
## Step 2: Render Text Files to Multi-Pages HTML
```csharp
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
/// <summary>
/// This example demonstrates how to render TXT document into HTML, JPG, PNG, PDF.
/// </summary>
public class RenderingTxt
{
public static void Run()
{
string outputDirectory = "Your Document Directory";
string pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.html");

// TO MULTI PAGES HTML
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);

viewer.View(options);
}

pageFileFullPath = Path.Combine(outputDirectory, "Txt_result_single_page.html");

// TO SINGLE HTML
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_2_TXT))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);
options.RenderToSinglePage = true;

viewer.View(options);
}

// TO JPG
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.jpg");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
JpgViewOptions options = new JpgViewOptions(pageFileFullPath);

viewer.View(options);
}

// TO PNG
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.png");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
PngViewOptions options = new PngViewOptions(pageFileFullPath);

viewer.View(options);
}

// TO PDF
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.pdf");

using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
PdfViewOptions options = new PdfViewOptions(pageFileFullPath);

viewer.View(options);
}

Console.WriteLine($"\nSource document rendered successfully.\nCheck output in {outputDirectory}.");
}
}
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);
viewer.View(options);
}
```
Instantiate a `Viewer` object with the path to the text file. Configure `HtmlViewOptions` for embedded resources and render the text file into multi-pages HTML.
## Step 3: Define Single-Page HTML Output Path
```csharp
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result_single_page.html");
```
Specify the full path for the single-page HTML output file.
## Step 4: Render Text Files to Single-Page HTML
```csharp
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_2_TXT))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(pageFileFullPath);
options.RenderToSinglePage = true;
viewer.View(options);
}
```
Instantiate a `Viewer` object with the path to the text file. Configure `HtmlViewOptions` for embedded resources and set `RenderToSinglePage` to true. Render the text file into a single-page HTML.
## Step 5: Define JPG Output Path
```csharp
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.jpg");
```
Specify the full path for the JPG output file.
## Step 6: Render Text Files to JPG
```csharp
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
JpgViewOptions options = new JpgViewOptions(pageFileFullPath);
viewer.View(options);
}
```
Instantiate a `Viewer` object with the path to the text file. Configure `JpgViewOptions` for the output path and render the text file into JPG format.
## Step 7: Define PNG Output Path
```csharp
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.png");
```
Specify the full path for the PNG output file.
## Step 8: Render Text Files to PNG
```csharp
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
PngViewOptions options = new PngViewOptions(pageFileFullPath);
viewer.View(options);
}
```
Instantiate a `Viewer` object with the path to the text file. Configure `PngViewOptions` for the output path and render the text file into PNG format.
## Step 9: Define PDF Output Path
```csharp
pageFileFullPath = Path.Combine(outputDirectory, "Txt_result.pdf");
```
Specify the full path for the PDF output file.
## Step 10: Render Text Files to PDF
```csharp
using (Viewer viewer = new Viewer(TestFiles.SAMPLE_TXT))
{
PdfViewOptions options = new PdfViewOptions(pageFileFullPath);
viewer.View(options);
}
```
Instantiate a `Viewer` object with the path to the text file. Configure `PdfViewOptions` for the output path and render the text file into PDF format.

## Conclusion
In conclusion, GroupDocs.Viewer for .NET empowers developers to effortlessly render text files into various formats, including HTML, JPG, PNG, and PDF. By following the step-by-step guide outlined in this article, you can seamlessly integrate GroupDocs.Viewer into your .NET applications, enhancing document management capabilities.
## FAQ's
### Q: Is GroupDocs.Viewer for .NET compatible with all versions of the .NET framework?
Yes, GroupDocs.Viewer for .NET is designed to be compatible with a wide range of .NET framework versions, ensuring versatility and flexibility in development.
### Q: Can I customize the output appearance of rendered documents?
Absolutely! GroupDocs.Viewer offers extensive customization options, allowing developers to tailor the appearance of rendered documents according to their preferences and requirements.
### Q: Is there a trial version available for GroupDocs.Viewer for .NET?
Yes, you can explore the functionalities of GroupDocs.Viewer for .NET by accessing the free trial available on the [website]( https://releases.groupdocs.com/).
### Q: How can I obtain support or seek assistance with GroupDocs.Viewer for .NET?
For any inquiries, support, or assistance regarding GroupDocs.Viewer for .NET, you can visit the dedicated support forum accessible [here](https://forum.groupdocs.com/c/viewer/9).
### Q: Can I purchase a temporary license for GroupDocs.Viewer for .NET?
Yes, temporary licenses are available for purchase, providing users with flexibility and convenience in utilizing GroupDocs.Viewer for .NET for specific durations.

0 comments on commit 93f46d2

Please sign in to comment.