---
title: "Convert Word pages to PNG in C#"
url: https://recursiveai.org/onedocument/cookbook/convert-docx-pages-to-png/
description: "Convert a Word DOCX to one PNG per page in C#. Select a page range and set the DPI without installing Word or creating an intermediate PDF."
version: "1.0.0"
---

# Convert Word pages to PNG in C#

**OneDocument** is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDocument.Rendering) · [GitHub](https://github.com/recursive-ai-oss/onedocument-csharp) · [Docs](https://recursiveai.org/onedocument/docs/) · [Download example (.zip)](https://recursiveai.org/onedocument/cookbook/convert-docx-pages-to-png/convert-docx-pages-to-png.zip)

Turn `atlas.docx` from the zip into PNGs, one per page, without a PDF.

```shell
dotnet add package RecursiveAI.OneDocument.Rendering
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneDocument.Documents;
using RecursiveAI.OneDocument.Rendering;

using var doc = Document.Open("atlas.docx");
var options = new PageExportOptions
{
    Pages = PageSelection.Parse("2-3"),
    Dpi = 150,
};
PageExporter.ExportPages(doc,
    PageImageFormat.Png, page =>
    File.WriteAllBytes($"page-{page.Number}.png",
        page.Data), options);
```

Writes `page-2.png` and `page-3.png`.

Unzip [the example](https://recursiveai.org/onedocument/cookbook/convert-docx-pages-to-png/convert-docx-pages-to-png.zip), then `dotnet run`.

## The full program

The sample has three US Letter pages, separated by explicit page breaks: “Atlas: overview,” “Atlas: north route” and “Atlas: south route.” The program prints each file’s name after writing it. At 150 DPI the PNGs are 1275 × 1650 pixels.

```csharp
using RecursiveAI.OneDocument.Documents;
using RecursiveAI.OneDocument.Rendering;

using var doc = Document.Open("atlas.docx");
var options = new PageExportOptions
{
    Pages = PageSelection.Parse("2-3"),
    Dpi = 150,
};
PageExporter.ExportPages(doc,
    PageImageFormat.Png, page =>
    {
        var name = $"page-{page.Number}.png";
        File.WriteAllBytes(name, page.Data);
        Console.WriteLine(name);
    }, options);
```

`dotnet run` prints:

```text
page-2.png
page-3.png
```

Page numbers start at 1. The end of a range is clipped to the last page, but a range starting past the last page throws `ArgumentOutOfRangeException`.

## Variations

**Export every page as a PNG 800 pixels wide.** Replace the `options` declaration in either example. The height follows the page’s proportions.

```csharp
var options = new PageExportOptions
{
    Pages = PageSelection.All,
    WidthPixels = 800,
};
```

The full program now prints:

```text
page-1.png
page-2.png
page-3.png
```

## Related recipes

- [Convert DOCX to PDF](https://recursiveai.org/onedocument/cookbook/convert-docx-to-pdf/)
- [Render a PowerPoint slide as PNG](https://recursiveai.org/onedocument/cookbook/render-powerpoint-slide-as-png/)
- [Read a Word document](https://recursiveai.org/onedocument/cookbook/read-word-document/)

---

## The short answer

To convert a Word DOCX to one PNG per page in C#, open the document and call `PageExporter.ExportPages` with `PageImageFormat.Png`. Set `Pages` to the range you want and `Dpi` to the desired resolution. The callback gets the original page number and the encoded bytes for that page. There’s no intermediate PDF and no Word automation.

## How do I convert a Word file to PNG without a PDF?

OneDocument lays out the DOCX to determine where text, pictures and other objects go on the page. It then draws each selected page and encodes it directly as PNG. Don’t use `SaveAs("page.png")` when you want several files: the image writer behind that call writes only the first page for PNG. Use `ExportPages` and give each output a different name using `page.Number`.

An export selects pages from the layout, not from a list of page images already stored in the DOCX. If a font is substituted, line breaks and page breaks can differ from those on a computer with the original font. For documents where that matters, look at `PageExportReport.Notes` for substitutions and layout notes. See the [font selection rules](https://recursiveai.org/onedocument/docs/layout/#fonts) for how fonts are resolved.

## How do I convert Word pages to high-resolution PNGs?

Use `Dpi` when you want a set number of pixels per inch of paper. At 150 DPI an 8.5 × 11 inch page is 1275 × 1650 pixels, as in the example. At 300 DPI both dimensions double, so there are four times as many pixels to draw. The default for PNG is 144 DPI. The exporter accepts 1 to 2400 DPI and caps each page at 100 million pixels, so the usable DPI also depends on paper size.

When you need a fixed width for thumbnails, set `WidthPixels` instead. Supply both `WidthPixels` and `HeightPixels` to fit a page inside a box without changing its proportions. The page area is white by default. See [page export options](https://recursiveai.org/onedocument/docs/rendering-export/#choosing-pages-size-and-encoder-settings) for background and encoder settings.
