Files
docx/docs/usage/text-frames.md
T
DolanandDolan Miu 74bf48f8c1 feat: Migrate to new component authoring (#3332)
* feat: Migrate to new component authoring

# Conflicts:
#	src/file/table-of-contents/table-of-contents.ts

# Conflicts:
#	src/file/content-types/content-types.ts
#	src/file/paragraph/properties.ts
#	src/file/table/table-properties/table-properties.ts

# Conflicts:
#	src/file/document/body/section-properties/section-properties.ts
#	src/file/paragraph/run/run.ts
#	src/file/table-of-contents/table-of-contents.ts
#	src/file/table/grid.ts
#	src/file/table/table-cell/table-cell-properties.ts
#	src/file/table/table.ts

* Clarify public api

* Add docs

* Fix tests and linting

* Fix readonly array

* Fix spelling

* Update ToC docs

* Update WPS to use BuilderElement

* Migrate components to use Builder element

Add ESLint rules

* Comment out the template demos

* Ignore demo 90 until we fix schema validation

* Disable demo validation

* Disable doc

* Disable validation for now

---------

Co-authored-by: Dolan Miu <>
2026-02-22 21:23:05 +00:00

1.8 KiB

Text Frames

Similar to Text Boxes!

!> Text Frames requires an understanding of Paragraphs.

Text frames are paragraphs of text in a document which are positioned in a separate region or frame in the document, and can be positioned with a specific size and position relative to non-frame paragraphs in the current document.

Intro

To make a Text Frame, simply add the frame property on a paragraph. Borders can be applied to frame simply by adding the border attribute.

new Paragraph({
    frame: {
        position: {
            x: 1000,
            y: 3000,
        },
        width: 4000,
        height: 1000,
        anchor: {
            horizontal: FrameAnchorType.MARGIN,
            vertical: FrameAnchorType.MARGIN,
        },
        alignment: {
            x: HorizontalPositionAlign.CENTER,
            y: VerticalPositionAlign.TOP,
        },
    },
    border: {
        top: {
            color: "auto",
            space: 1,
            value: "single",
            size: 6,
        },
        bottom: {
            color: "auto",
            space: 1,
            value: "single",
            size: 6,
        },
        left: {
            color: "auto",
            space: 1,
            value: "single",
            size: 6,
        },
        right: {
            color: "auto",
            space: 1,
            value: "single",
            size: 6,
        },
    },
    children: [
        new TextRun("Hello World"),
        new TextRun({
            text: "Foo Bar",
            bold: true,
        }),
        new TextRun({
            text: "\tGithub is the best",
            bold: true,
        }),
    ],
});

Demo

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/61-text-frame.ts