PPTX

Shapes and Text

Create shapes with formatted text, paragraphs, alignment, lists, and text fitting

Shapes are the primary building blocks of a slide. A Shape can contain text through Paragraph and TextRun objects.

Basic Shape

import { Shape } from "@office-open/pptx";

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 3,
    text: "Simple text",
});

Geometry Presets

Use the geometry option to set the shape type:

new Shape({ geometry: "rect" }); // Rectangle (default)
new Shape({ geometry: "ellipse" }); // Ellipse / circle
new Shape({ geometry: "roundRect" }); // Rounded rectangle
new Shape({ geometry: "triangle" });
new Shape({ geometry: "diamond" });
new Shape({ geometry: "star5" });
new Shape({ geometry: "hexagon" });
new Shape({ geometry: "chevron" });
new Shape({ geometry: "arrow" });

Paragraphs and Text Runs

Use paragraphs for full control over text formatting:

new Shape({
    x: 1,
    y: 1,
    width: 6,
    height: 3,
    paragraphs: [
        new Paragraph({
            children: [
                new TextRun({ text: "Bold title", bold: true, fontSize: 28, color: "2E74B5" }),
            ],
        }),
        new Paragraph({
            children: [
                new TextRun({ text: "Normal text with " }),
                new TextRun({ text: "italic", italics: true }),
                new TextRun({ text: " and " }),
                new TextRun({ text: "colored", color: "FF0000", underline: {} }),
            ],
        }),
    ],
});

TextRun Formatting Options

new TextRun({
    text: "Formatted text",
    fontSize: 24, // Size in points
    bold: true,
    italics: true,
    underline: {}, // Single underline
    color: "4472C4", // Hex color without #
    font: "Calibri", // Font family
    break: 1, // Line break count
});

Alignment

new Paragraph({
    alignment: "left", // "left" | "center" | "right" | "justify"
    children: [new TextRun({ text: "Aligned text" })],
});

Bullet Lists

new Shape({
    x: 1,
    y: 1,
    width: 6,
    height: 4,
    paragraphs: [
        new Paragraph({
            bullet: true,
            children: [new TextRun({ text: "First item" })],
        }),
        new Paragraph({
            bullet: true,
            children: [new TextRun({ text: "Second item" })],
        }),
        new Paragraph({
            bullet: { type: "number" },
            children: [new TextRun({ text: "Numbered item" })],
        }),
    ],
});

Text Anchor (Vertical Alignment)

Control vertical positioning of text within the shape:

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 3,
    textAnchor: "top", // "top" | "middle" | "bottom"
    text: "Top-aligned text",
});

Auto-Fit Text

new Shape({
    x: 1,
    y: 1,
    width: 4,
    height: 2,
    text: "This text will shrink to fit the shape",
    textAutoFit: "shrink",
    // or textAutoFit: "resize" to resize the shape
});

Rotation and Flip

new Shape({
    x: 1,
    y: 1,
    width: 3,
    height: 2,
    rotation: 45, // Degrees
    flip: "vertical", // "horizontal" | "vertical" | "both"
    text: "Rotated shape",
});

Text Columns

new Shape({
    x: 1,
    y: 1,
    width: 8,
    height: 4,
    textColumns: { count: 2, spacing: 0.5 },
    paragraphs: [
        new Paragraph({ children: [new TextRun({ text: "Column 1 content..." })] }),
        new Paragraph({ children: [new TextRun({ text: "Column 2 content..." })] }),
    ],
});

Text Margins

new Shape({
    x: 1,
    y: 1,
    width: 6,
    height: 3,
    textMargins: { top: 0.2, bottom: 0.2, left: 0.3, right: 0.3 },
    text: "Text with custom margins",
});
Copyright © 2026