Quickly Convert Word (.docx) to Image (.jpg) with C#/VB.NET

Image appears everywhere in our daily life. Comparing with plain text, image is more appealed to people. Therefore, it seems that images become one of the most important parts of advertisements, booklets and many electronic documents, even e-books and magazines.

Generally speaking, there are many methods to have an image, for example, to draw, print screen or find one from internet. Also, sometimes, we can find that the contract which is sent to partner is not an electronic file but an image because image is difficult to edit. At that time, people may need to convert a document to image firstly.

In this post, I will share a method about how to convert Word to Image with C#/VB.NET. Actually, there are several formats for image, and I set the image format which is converted from Word as .jpg.

What’s more, I use a component, Spire.Doc for .NET to realize conversion more quickly and easily. So I have added its dll file as reference in my project at the beginning.

Detailed Steps Shown as Following:           

I. Load document which I want to convert to image from computer by using document.LoadFromFile() method.

C#

            Document document = new Document();
            document.LoadFromFile(@”E:\Work\Antarctic.docx”);

VB.NET

            Dim document As New Document()
            document.LoadFromFile(“E:\Work\Antarctic.docx”)

II. Declare image and define its location and image type by using document.SaveToImages() method. Two parameters should be passed to this method, page index and image type.

C#

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

VB.NET

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

III. Save image by using image.Save() method and launch this image.  

C#

            image.Save(“toimage.jpg”);
            System.Diagnostics.Process.Start(“toimage.jpg”);

VB.NET

            image.Save(“toimage.jpg”)
            System.Diagnostics.Process.Start(“toimage.jpg”)

Note: Because the image type is set as Metafile in step 2, so the image format cannot be set as .bmp and .tiff.  For ,bmp and .tiff format, please change image type as bitmap (ImageType.Bitmap)

For DOC to image, just need to change the file format as .doc which is loaded in first step.

Result Shown as Following:

Freely Download .NET Word Component

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

3 thoughts on “Quickly Convert Word (.docx) to Image (.jpg) with C#/VB.NET”

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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