> ## 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 PDF

The PDF is painted from the same layout that the editor and the PNG export use. Text stays text: it is selectable and searchable, and the fonts are embedded as subsets.

## Node: one call

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

const doc = await WordDocument.open("input.docx");
await doc.toPdf("output.pdf");
```

`toPdf(path?)` returns the bytes too, so you can stream them instead of writing a file:

```ts theme={null}
const pdf = await doc.toPdf(); // Uint8Array
return new Response(pdf, { headers: { "content-type": "application/pdf" } });
```

## Node: show tracked changes and comments

`toPdf` paints the **final** view by default, as Word prints with *No Markup*. To print the redline (insertions underlined, deletions struck through, comments in a margin), pass the review view, with the same names and values as the docserver page images:

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

const doc = await WordDocument.open("redline.docx");
await doc.toPdf("redline.pdf", {
  trackedChanges: "inline", // "final" (default) | "inline" | "balloons"
  comments: "balloons",     // "hidden" (default) | "balloons"
});
```

| Option | Values |
| - | - |
| `trackedChanges` | `"final"` (default): changes accepted, no marks. `"inline"`: insertions and deletions marked in the text. `"balloons"`: revisions in a right margin, as Word's *Show Revisions in Balloons* |
| `comments` | `"hidden"` (default). `"balloons"`: comments in a right margin |

In the balloons view, a balloon that does not fit the margin is cut and marked `... [n]`. Its full text prints on extra pages after the body, as Word prints it.

Any other value throws, so a misspelled option never prints the final view by mistake. Simple Markup and Original are not offered.

A review view has its own layout. Printing it does not lay out again the pages that `getPageCount` and the default `toPdf` read. After an edit, the next print of the same view lays out only what changed. `toPng` takes the same two options.

To print without `WordDocument`, use the pipeline and set the view:

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

const { bytes } = await convertDocxToPdf("redline.docx", {
  trackedChanges: "inline", // "final" (default) | "inline" | "balloons"
  comments: "balloons",     // "hidden" (default) | "balloons"
});
await writeFile("redline.pdf", bytes);
```

The PDF embeds the faces that the layout measured.

## Browser

```ts theme={null}
import { WordDocument, browserLayoutHost, portableFaceProvider } from "@reductoai/docx/browser";

browserLayoutHost({ fonts: portableFaceProvider((file) => `/fonts/${file}`) });

const doc = await WordDocument.fromBytes(bytes);
const pdf = await doc.toPdf();
const url = URL.createObjectURL(new Blob([pdf], { type: "application/pdf" }));
```

For a redline PDF in the page, pass `trackedChanges: "inline"` and `comments: "balloons"` to `browserLayoutHost`.

### Without OfficeJS

If you only convert and do not edit, lay out the bytes and paint the result:

```ts theme={null}
import { layoutDocxInBrowser, portableFaceProvider, renderPdfInBrowser } from "@reductoai/docx/browser";

const fonts = portableFaceProvider((file) => `/fonts/${file}`);
const ir = await layoutDocxInBrowser(bytes, { fonts, name: "input.docx" });
const { bytes: pdf } = await renderPdfInBrowser(ir, fonts);
```

`renderPdfInBrowser` fetches the fallback face before it paints, so a missing glyph still has a face to embed.

## Options

`toPdf` and `renderPdfBytes` take `RenderPdfOptions`; node `toPdf` also takes `trackedChanges` and `comments` (above):

| Option | Notes |
| - | - |
| `paintPages` | 1-based pages to paint. Other pages stay in the file at their true size, but blank |
| `onProgress` | Phase and per-page progress events |
| `signal` | An `AbortSignal` that stops the render between pages |

## Accuracy

Each release is checked page by page against PDFs that Microsoft Word exports, on a corpus of real documents. The layout follows Word's rules for line breaks, tables, floats, footnotes, fields and section breaks. To see what one document uses and how well we support each feature, inspect it before you render:

```ts theme={null}
import { inspectCompatibility } from "@reductoai/docx";

const report = await inspectCompatibility(bytes, { target: "render" });
for (const c of report.capabilities) {
  if (c.support !== "full") console.log(c.title, c.support, c.limitations);
}
```

> [!NOTE]
>
> Results depend on fonts. With the portable profile, line breaks match Word's when the document uses Office fonts that have a metric clone (Calibri, Cambria, Arial, Times New Roman, Courier New, Georgia, Segoe UI). See [Fonts](https://docs.reducto.ai/office/docx/getting-started/fonts.md).
