How to Convert Word Document to Image for C#/VB.NET

Microsoft Word can save Word document as different file formats such as XML, HTML, Dot, etc. But unfortunately it doesn’t support saving Word document as an image. Sometimes we need convert Word document to Image for a better show. Actually we have a lot of solutions to convert Word document to image. We can use free online converter for a fast conversion and commercial Word converter with additional settings, or we can just give a screenshot on Word document. Here, I am giving another solution which use C#/VB.NET convert Word document to image.

This solution need a .NET component, Spire.Doc which is a MS Word component which enables user to perform a wide range of Word document processing tasks directly, such as generate, read, write and modify Word document for .NET and Silverlight.

Convert Word document to Image by using C#/VB.NET is very easy. Now, follow the simple steps below.

Step 1

Download Spire.Doc and install on system. Please also make sure Visual Studio is correctly installed on your system.

Step 2

Create a project in Visual Studio and add Spire.Doc DLL as reference.

Step 3

Use the following code to load local Word document which we need convert to Image.

    Document document = new Document();
    document.LoadFromFile(@"..\Sample.doc");

Step 4

Use the following code to save Word document to a BMP image.

    Image img = document.SaveToImages(0, ImageType.Bitmap);
    img.Save("sample.bmp");

Full Simple C# Code:

private void button1_Click(object sender, EventArgs e)
{
    //Create word document
    Document document = new Document();
    document.LoadFromFile(@"..\Sample.doc");

    //Save doc file.
    Image img = document.SaveToImages(0, ImageType.Bitmap);
    img.Save("sample.bmp");

    //Launching the image file.
    WordDocViewer("sample.bmp");
}

private void WordDocViewer(string fileName)
{
    try
    {
        System.Diagnostics.Process.Start(fileName);
    }
    catch { }
}

Full Simple VB.NET Code:

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
       'Create word document
       Dim document_Renamed As New Document()
       document_Renamed.LoadFromFile("..\Sample.doc")

       'Save doc file.
       Dim img As Image = document_Renamed.SaveToImages(0, ImageType.Bitmap)
       img.Save("sample.bmp")

       'Launching the image file.
       WordDocViewer("sample.bmp")
End Sub
Private Sub WordDocViewer(ByVal fileName As String)
       Try
              Process.Start(fileName)
       Catch
       End Try
End Sub

Effective Screenshot

More about Spire.Doc

As a professional and powerful Word component, Spire.Doc doesn’t need Microsoft Office Word Automation but also allows user to directly operate Word document, format and style and insert content to Word document. Spire.Doc which with high quality, powerful functions and cheap price supports Word 97, Word 2003, Word 2007 and Word 2010. Click to learn more…

Leave a Reply