In various cases, you have to convert the text into read-only formats such as images or PDF. In a previous article, we covered how to convert the text in a TXT file to PDF. For text to image conversion from within .NET applications, this article shows how to convert a text to PNG, JPEG, or GIF image programmatically in C# .NET.
Convert Text to PNG, JPEG, or GIF Images in C# - .NET API
To convert text to PNG, JPEG, or GIF images, we will use Aspose.Words for .NET. It is a powerful API that allows you to create and manipulate MS Word documents. Moreover, it lets you convert MS Word and text documents to various other file formats. You can download the API’s DLL or install it directly from NuGet.
PM> Install-Package Aspose.Words
Convert Text (TXT) to Image in C#
TXT files are the simplest and easiest way to store plain text without any formatting. Therefore, we will use a TXT file and convert its text into PNG, JPEG, or GIF images. The following are the steps to convert text to image in C#.
- Load the text file using the Document class.
- Loop through all the pages in the document.
- Extract each page using Document.ExtractPages() method.
- Save page as PNG (or another image format) using Document.Save() method.
The following code sample shows how to convert a text to images in C#.
Get a Free API License
You can get a temporary license in order to use Aspose.Words for .NET without evaluation limitations.
In this article, you have learned how to convert text to image programmatically in C#. You can use the provided code sample and convert the text in TXT files to PNG, JPEG, or GIF images seamlessly. Besides, you can explore other features offered by Aspose.Words for .NET using the documentation. Also, you can post your questions on our forum.