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

# .xlsx to PDF

`toPdf` paints each sheet as the Copy Picture command in Microsoft Excel paints it: the cells as on screen, with charts and pictures. It paints row and column headers only when you set `labels: true`. It needs `skia-canvas` and `@reductoai/portable-fonts` (see [Installation](https://docs.reducto.ai/office/xlsx/getting-started/installation.md)).

`toPdf` is in `@reductoai/xlsx/node` only. To get a picture in the browser, see [PNG](https://docs.reducto.ai/office/xlsx/rendering/png.md#in-the-browser-from-a-view).

## Every sheet

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/node";

const book = await ExcelWorkbook.open("model.xlsx");
await book.toPdf("model.pdf"); // one page for each visible sheet
```

Without a path, `toPdf` returns the bytes and does not write a file:

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/node";

const book = await ExcelWorkbook.open("model.xlsx");
const pdf: Uint8Array = await book.toPdf();
```

## One sheet

Give the sheet names or zero-based indexes in `sheets`. Each sheet is one page, in the order you give.

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/node";

const book = await ExcelWorkbook.open("model.xlsx");
await book.toPdf("summary.pdf", { sheets: ["Summary"] });
await book.toPdf("two.pdf", { sheets: ["Summary", 2] });
```

## One range

Give an A1 range in `range`. Put the sheet name before `!`, and the PDF has one page. Without a sheet name, each sheet in `sheets`, or each visible sheet, gives one page of that range.

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/node";

const book = await ExcelWorkbook.open("model.xlsx");
await book.toPdf("table.pdf", { range: "Summary!A1:H30" });
```

## Options

| Option | Default | Notes |
| - | - | - |
| `sheets` | every visible sheet | Sheet names or zero-based indexes |
| `range` | each sheet's used cells | One A1 range, such as `"Summary!A1:H30"`. With a sheet name, `sheets` is not used |
| `gridlines` | `false` | `true` paints the gridlines. Excel's Copy Picture and print do not paint them |
| `labels` | `false` | `true` adds column letters and row numbers (see [Labels](https://docs.reducto.ai/office/xlsx/rendering/png.md#labels)) |

Each page is the size of its sheet's picture, at 0.75 points for each sheet pixel. `toPdf` does not divide a sheet into printed pages. A page holds at most 1,000 rows and 100 columns (see [Limits](https://docs.reducto.ai/office/xlsx/rendering/png.md#limits)).
