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

# JS API in Node

Import from `@reductoai/pptx/node`. It gives a `PowerPointPresentation` that reads and writes files and renders with the fonts on the machine.

## Open, edit, save

```ts theme={null}
import { PowerPointPresentation } from "@reductoai/pptx/node";

const deck = await PowerPointPresentation.open("deck.pptx");
const slide = deck.slides.getItemAt(0);

for (const shape of slide.shapes.items) {
  const frame = shape.getTextFrameOrNullObject();
  if (frame.isNullObject || !frame.hasText) continue;
  if (frame.textRange.text === "DRAFT") frame.textRange.text = "FINAL";
}

slide.shapes.addTextBox("Approved", { left: 40, top: 40, width: 200, height: 40 });
await deck.save("deck-edited.pptx");
```

`save` always needs a path. The facade never writes over the input file by itself.

Setting `TextRange.text` keeps the formatting of the first replaced character, as Microsoft PowerPoint does.

## Create a new deck

```ts theme={null}
const deck = await PowerPointPresentation.create();

// A new deck has no slides. `add()` uses the first layout of the first master.
const slide = deck.slides.add();

const box = slide.shapes.addTextBox("Quarterly report", { left: 40, top: 40, width: 400, height: 60 });
box.textFrame.textRange.font.bold = true;
box.textFrame.textRange.font.size = 24;
box.textFrame.textRange.font.color = "#C00000";

slide.shapes
  .addGeometricShape("Rectangle", { left: 40, top: 120, width: 120, height: 60 })
  .fill.setSolidColor("#1F4E79");

slide.shapes.addTable(3, 2, {
  left: 40,
  top: 200,
  width: 400,
  values: [
    ["Region", "Revenue"],
    ["EMEA", "4.2M"],
    ["APAC", "3.1M"],
  ],
});

slide.notes.text = "Open with the revenue table.";
await deck.save("report.pptx");
```

To pick a layout, pass its id: `deck.slides.add({ layoutId: deck.slideMasters.getItemAt(0).getLayoutByName("Blank").id })`. See [Blank decks](https://docs.reducto.ai/office/pptx/recipes/blank-decks.md).

## Bytes in, bytes out

When the deck comes from a request or a bucket, use bytes:

```ts theme={null}
const deck = await PowerPointPresentation.fromBytes(new Uint8Array(await file.arrayBuffer()));
// ... edit ...
const bytes = await deck.toBytes();
```

## Render

```ts theme={null}
await deck.toPdf("deck.pdf");                            // writes the file, also returns the bytes
const pngs = await deck.toPng({ pages: [0], scale: 2 });  // [{ page, png, width, height }]
```

Both render the **current** edit state. You do not need to save first. See [PDF](https://docs.reducto.ai/office/pptx/conversion/pdf.md) and [PNG](https://docs.reducto.ai/office/pptx/conversion/png.md).

## Common tasks

```ts theme={null}
const slide = deck.slides.getItemAt(0);

// Slides
const copy = deck.slides.add({ index: 1 });
copy.moveTo(0);
deck.slides.getItemAt(2).delete();
slide.slideShowTransition.hidden = true;

// Text
const range = slide.shapes.getItemAt(0).textFrame.textRange;
range.font.name = "Arial";
range.font.size = 18;
range.paragraphFormat.horizontalAlignment = "Center";
range.getSubstring(0, 5).setHyperlink({ address: "https://example.com" });

// Sections
deck.sections.add("Appendix", slide);

// Slides from another deck
const ids = await deck.insertSlidesFromBase64(otherDeckBytes, { formatting: "UseDestinationTheme" });
```
