3 Easy Ways to Convert Word Documents to Images in C#
Tags: csharp, development, essentialstudio, fileformats
Published: 2022-12-01 14:09:58

---
title: 3 Easy Ways to Convert Word Documents to Images in C#
published: true
date: 2022-12-01 12:42:48 UTC
tags: csharp, development, essentialStudio, fileformats
canonical_url: https://www.syncfusion.com/blogs/post/convert-word-documents-to-images-in-csharp.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tb8led04w9mkyvlc0y1c.png
---
In situations like downloading a huge Word document, we sometimes want to preview one or more pages of the document before downloading it. You can easily convert pages of a Word document into images to preview them without the help of MS Word.

The Syncfusion [.NET Core Word Library](https://www.syncfusion.com/document-processing/word-framework/net-core "Syncfusion .NET Core Word Framework") (DocIO) can programmatically convert any Word document into images with just a few lines of code in C#. This library does not need Microsoft Word or any interop dependencies. With this functionality, you can easily preview Word documents in applications and share the images for printing.

This Word-to-image conversion is available in multiple environments such as:

- Windows
- Linux
- macOS
- Mobile devices
- Docker
- Cloud computing environments

![Word to PDF conversion in csharp](https://www.syncfusion.com/blogs/wp-content/uploads/2022/12/Word-to-PDF-conversion-in-csharp.png)

This conversion function supports all the elements of a typical Word document: text, formatting, images, tables, hyperlinks, fields, table of contents, shapes, headers, footers, etc. You can convert commonly used Word file formats such as DOC, DOCX, and RTF into images and save them in different image formats like PNG, JPEG, and BMP.

**Note:** For more details, refer to our documentation on [Converting Word documents to images in C#](https://help.syncfusion.com/file-formats/docio/word-to-image "Converting Word document to Image in Word Library documentation").

In this blog, we are going to discuss these options available in our Syncfusion .NET Core Word Library for Word-to-image conversion with code examples:

- [Convert entire pages in a Word document to images.](#convert-entire-pages-in-a-word-document-to-images)
- [Convert the first page of a Word document to an image.](#convert-the-first-page-of-a-word-document-to-an-image)
- [Convert a specific range of pages to images.](#convert-a-specific-range-of-pages-to-images)

Let’s get started with the implementation!

## Getting started

**Step 1:** First, create a new C# .NET Core **Console**  **App** in [Visual Studio](https://visualstudio.microsoft.com/ "Visual Studio").

**![Create a new C# .NET Core Console Application](https://www.syncfusion.com/blogs/wp-content/uploads/2022/12/Create-a-new-C-.NET-Core-Console-Application-1.png)Step 2:** Then, install the [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core "Syncfusion.DocIORenderer.Net.Core NuGet package") NuGet package as a reference to the app from [NuGet Gallery](https://www.nuget.org "NuGet Gallery").

![Install the Syncfusion.DocIORenderer.Net.Core NuGet package](https://www.syncfusion.com/blogs/wp-content/uploads/2022/12/Install-the-Syncfusion.DocIORenderer.Net_.Core-NuGet-package-1.png)

**Step 3:** Now, include the following namespaces in the **Program.cs** file.

```csharp
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
```

The project is ready! Let’s write the code to convert a Word document into an image.

## Convert all the pages in a Word document into images

With our .NET Core Word Library, you can easily convert all the pages of a Word document into images using the **RenderAsImages** method of the **WordDocument** instance.

Refer to the following code example.

```csharp
//Open the file as Stream.
using (FileStream docStream = new FileStream("Template.docx", FileMode.Open, FileAccess.Read))
{
  //Load an existing Word document.
  using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Automatic))
  {
    //Convert an entire Word document to images.
    Stream[] imageStreams = wordDocument.RenderAsImages();
    for (int i = 0; i < imageStreams.Length; i++)
    {
      //Save the stream as a file.
      using (FileStream fileStreamOutput = File.Create("WordToImage_" + i + ".jpeg"))
      {
        imageStreams[i].CopyTo(fileStreamOutput);
      }
    }
  }
}
```

By executing the previous code example, we will get output like in the following screenshot.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2022/12/Converting-all-pages-in-a-Word-document-to-images.png" alt="Converting all pages in a Word document to images" style="width:100%">

  <figcaption>Converting all pages in a Word document to images</figcaption>

</figure>

## Convert the first page of a Word document to an image

If you’re dealing with a large document, you might decide to just export the first page or any single page of it as an image for previewing. You can use the **RenderAsImage** method of the **WordDocument** instance with an overload to provide the index of the page to be exported as image. To convert the first page of the Word document into an image, use the index value 0.

Refer to the following code example.

```csharp
//Open the file as Stream.
Using (FileStream docStream = new FileStream(“Template.docx”, FileMode.Open, FileAccess.Read))
{
  //Load an existing Word document.
  Using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Automatic))
  {
    //Convert the first page of the Word document into an image.
    Stream imageStream = wordDocument.RenderAsImages(0, ExportImageFormat.Jpeg);
    //Save the stream as a file.
    using (FileStream fileStreamOutput = File.Create("WordToImage.jpeg"))
    {
       imageStream.CopyTo(fileStreamOutput);
    }
  }
}

```

By executing this code example, we will get output like in the following screenshot.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2022/12/Converting-the-first-page-of-a-Word-document-to-an-image-for-previewing-1.png" alt="Converting the first page of a Word document to an image for previewing" style="width:100%">

  <figcaption>Converting the first page of a Word document to an image for previewing</figcaption>

</figure>

## Convert a specific range of pages to images

You may wish to export a range of pages as images in a Word document. For this, use the **RenderAsImages** method of the **WordDocument** instance with an overload that accepts two-page indices. The first parameter is the start-page index, and the second parameter is the end-page index. The pages that fall in this range will be converted into images.

Refer to the following code example.

```csharp
//Open the file as Stream.
Using (FileStream docStream = new FileStream(“Template.docx”, FileMode.Open, FileAccess.Read))
{
  //Load an existing Word document.
  Using (WordDocument wordDocument = new WordDocument(docStream, FormatType.Automatic))
  {
    //Convert a specific range of pages in a Word document to images.
    Stream[] imageStreams = wordDocument.RenderAsImages(1, 2);
    for (int I = 0; i < imageStreams.Length; i++)
    {
      //Save the stream as a file.
      using (FileStream fileStreamOutput = File.Create“"WordToImage”" + i +“".jpe”"))
      {
        imageStreams[i].CopyTo(fileStreamOutput);
      }
    }
  }
}
```

## GitHub reference

You can find all the examples for [converting Word documents to images using Syncfusion .NET Core Word Library](https://github.com/SyncfusionExamples/convert-word-to-image "Converting Word documents to Image in C# GitHub demo") in the GitHub repository.

## Conclusion

Thanks for reading this blog. We have seen how to easily convert Word documents into images easily using the [Syncfusion .NET Core Word Library](https://www.syncfusion.com/document-processing/word-framework/net-core "Syncfsion .NET Core Word Framework"). Take a moment to peruse the [documentation](https://help.syncfusion.com/file-formats/docio/word-to-image "Converting Word document to Image in Word Library documentation"), where you’ll find other options and features, all with accompanying code examples.

Apart from this Word-to-image conversion functionality, our Syncfusion .NET Word Library (DocIO) has the following significant functionalities and many more:

- Create, read, and edit Word documents programmatically.
- Create complex reports by merging data into a Word template from various data sources through [mail merge](https://help.syncfusion.com/file-formats/docio/working-with-mail-merge "Help Documentation on Working with Mail merge").
- [Merge](https://help.syncfusion.com/file-formats/docio/word-document/merging-word-documents "Working with mail merge in .NET Core Word Library documentation"), [split](https://help.syncfusion.com/file-formats/docio/word-document/split-word-documents "Help Documentation on Split Word documents"), and organize Word documents.
- Convert Word documents into [PDF](https://help.syncfusion.com/file-formats/docio/word-to-pdf "Converting Word document to PDF in .NET Core Word Library documentation"), [image](https://help.syncfusion.com/file-formats/docio/word-to-image "Converting Word document to Image in .NET Core Word Library documentation"), [HTML](https://help.syncfusion.com/file-formats/docio/html "Word to HTML and HTML to Word conversions in .NET Core Word Library documentation"), [RTF](https://help.syncfusion.com/file-formats/docio/rtf "RTF conversions in .NET Core Word Library documentation"), and other formats.

You can find more Word Library examples at this [GitHub location](https://github.com/SyncfusionExamples/DocIO-Examples "Syncfusion .NET Core Word Library demos on GitHub").

Are you already a Syncfusion user? You can download the product setup [here](https://www.syncfusion.com/account/downloads/studio/ "License and download page of Essential Studio"). If you’re not yet a Syncfusion user, you can download a [30-day free trial](https://www.syncfusion.com/downloads/fileformats/confirm "Free evaluation of the Syncfusion Essential Studio").

If you have questions, contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [support portal](https://support.syncfusion.com/ "Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback/word "Syncfusion Feedback Portal"). We are always happy to assist you!

## Related blogs

- [Review Word Documents with Track Changes and Comments in a Web Application](https://www.syncfusion.com/blogs/post/review-word-documents-track-changes-and-comments-in-web-application.aspx "Blog: Review Word Documents with Track Changes and Comments in a Web Application")
- [Create and Update Table of Contents in Word Documents in .NET Core [C#]](https://www.syncfusion.com/blogs/post/create-and-update-table-of-contents-in-word-documents-in-net-core-c.aspx "Blog: Create and Update Table of Contents in Word Documents in .NET Core [C#]")
- [Document Editing Made Easy: Syncfusion Word Processor + Wisej](https://www.syncfusion.com/blogs/post/document-editing-made-easy-syncfusion-word-processor-wisej.aspx "Blog: Document Editing Made Easy: Syncfusion Word Processor + Wisej")
- [Easily Create a Fillable Form Using JavaScript Word Processor](https://www.syncfusion.com/blogs/post/easily-create-a-fillable-form-using-javascript-word-processor.aspx "Blog: Easily Create a Fillable Form Using JavaScript Word Processor")