Files
docx-js/usage/text-frames.md
2024-11-28 10:34:14 +00:00

1.7 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,
        }),
    ],
});