> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# DOCX to PNG

## Node

```ts theme={null}
import { writeFile } from "node:fs/promises";
import { WordDocument } from "@reductoai/docx/node";

const doc = await WordDocument.open("input.docx");
const pages = await doc.toPng({ scale: 2 }); // every page

for (const { page, png, width, height } of pages) {
  await writeFile(`page-${page}.png`, png);
  console.log(page, width, height);
}
```

| Option | Default | Notes |
| - | - | - |
| `pages` | every page | 1-based page numbers, for example `[1, 3]` |
| `scale` | `2` | Pixels per CSS pixel. `1` gives 96 dpi (816 × 1056 for US Letter); `2` gives 192 dpi |
| `trackedChanges` | `"final"` | `"inline"` or `"balloons"` paints Word's markup, as [`toPdf`](https://docs.reducto.ai/office/docx/conversion/pdf#node-show-tracked-changes-and-comments) does |
| `comments` | `"hidden"` | `"balloons"` paints comments in a right margin |

`png` is the encoded file. The PNG and the PDF come from the same layout, so they agree.

## Browser

A page paints the layout on a `<canvas>`. Then you encode the canvas.

### From the editor

If you show the document in [the editor](https://docs.reducto.ai/office/docx/ui/editor.md), the pages are already on screen:

```ts theme={null}
const pngs = await editor.model.toPng({ pages: [1], scale: 2 });
// [{ page, width, height, png: Blob }]
```

### From a layout

Without the editor, lay out the document and paint it with the viewer. With a bundler other than Vite, webpack or Next.js, first give the engine's URL. See [The layout engine](https://docs.reducto.ai/office/docx/js-api/browser.md#the-layout-engine).

```ts theme={null}
import { layoutDocxInBrowser, portableFaceProvider } from "@reductoai/docx/browser";
import { renderPagePngs } from "@reductoai/viewer/page-png";

const fonts = portableFaceProvider((file) => `/fonts/${file}`);
const ir = await layoutDocxInBrowser(bytes, { fonts });

const pngs = await renderPagePngs(ir, {
  pages: [1, 2],
  scale: 2,
  fontBytes: (id) => fonts.bytes(id),
});
```

Pass `fontBytes`. Without it, the canvas uses a local font with the same family name, and the text no longer sits where the layout put it.

See [Canvas viewer](https://docs.reducto.ai/office/docx/ui/canvas-viewer.md) for `@reductoai/viewer`.

## Thumbnails

For a small preview, paint at a low scale:

```ts theme={null}
const [thumb] = await doc.toPng({ pages: [1], scale: 0.25 });
```
