Convenient Solution to Convert RTF to Image (.jpg) in C# and Visual Basic

Document conversion is always the hot topic among developers and there are lots of powerful and easy-to-use converters released. Why is document conversion so popular? It is very helpful for users to read one document in other applications if there is no viewer of original document format installed on users’ system. In this post, I will introduce a solution about document conversion: RTF to Image in C# and Visual Basic.

RTF (Rich Text Format) describe contents with plain text and can save variety of information with different formats. It can be created by many applications, such as MS Word, Wordpad etc. The feature of RTF is compatibility so that it can be a wonderful document converter. Image, great tool to decorate contents, has many formats, including .jpg, .png, .gif, .bmp etc. In this example, the RTF will be converted to .jpg file.

This solution is based on a .NET Word component, Spire.Doc for .NET. So I have installed it on my system and added its dll as reference in my project.

Firstly, load the RTF document through invoking Document.LoadFromFile method. The overloads passed are fileName string and FileFormat.

Secondly, convert RTF to image (.jpg format). Invoke Document.SaveToImages method to save specified page of RTF file to image. The overloads to this method are pageIndex and ImageType. Because I want to save the image as .jpg format, so the ImageType is set as Bitmap. The other image types provided are shown as the following screenshot.

Assign the method result as value for Image instance and then invoke Image.Save method to save this converted image. The overloads passed are string fileName and ImageFormat. Select ImageFormat as Jpeg.



using System.Drawing;

using System.Drawing.Imaging;

using Spire.Doc;

using Spire.Doc.Documents;


namespace RTF2Image


    class Program


        static void Main(string[] args)


            //Load RTF Document

            Document document = new Document();

            document.LoadFromFile(@”E:\Work\Documents\WordDocuments\Blues Introduction.rtf”, FileFormat.Rtf);


            //Save to Image

            Image image = document.SaveToImages(0, ImageType.Bitmap);

            image.Save(“RTF2Image.jpg”, ImageFormat.Jpeg);






Visual Basic

Imports System.Drawing

Imports System.Drawing.Imaging

Imports Spire.Doc

Imports Spire.Doc.Documents


Namespace RTF2Image

    Friend Class Program

        Shared Sub Main(ByVal args() As String)

            ‘Load RTF Document

            Dim document As New Document()

            document.LoadFromFile(“E:\Work\Documents\WordDocuments\Blues Introduction.rtf”, FileFormat.Rtf)


            ‘Save to Image

            Dim image As Image = document.SaveToImages(0, ImageType.Bitmap)

            image.Save(“RTF2Image.jpg”, ImageFormat.Jpeg)


        End Sub

    End Class

End Namespace

After debugging, we can the converted image from RTF below:

Download Spire.Doc for .NET Here

P.S. The .NET Office component, Spire.Office for .NET can be used to realize this function as well.


One thought on “Convenient Solution to Convert RTF to Image (.jpg) in C# and Visual Basic

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s