DOCX
Text Boxes
Floating text boxes with VML positioning and styling
Text boxes are floating containers rendered via VML (v:shape). Add one as a section child using the textbox key — it accepts shape positioning (style), paragraph-level properties (border, shading), and children (the body content).
Basic Text Box
{
"sections": [
{
"children": [
{ "paragraph": { "children": ["Body paragraph beside the text box."] } },
{
"textbox": {
"style": {
"width": "2in",
"height": "1in",
"position": "absolute",
"marginLeft": "1in",
"marginTop": "0.5in",
"wrapStyle": "square"
},
"children": [{ "paragraph": { "children": ["Text inside the floating box."] } }]
}
}
]
}
]
}
import { generateDocument } from "@office-open/docx";
await generateDocument({
sections: [
{
children: [
{ paragraph: { children: ["Body paragraph beside the text box."] } },
{
textbox: {
style: {
width: "2in",
height: "1in",
position: "absolute",
marginLeft: "1in",
marginTop: "0.5in",
wrapStyle: "square",
},
children: [{ paragraph: { children: ["Text inside the floating box."] } }],
},
},
],
},
],
});
Textbox Options
A textbox is a section child combining paragraph-level properties with shape geometry:
| Option | Type | Description |
|---|---|---|
style | VmlShapeStyle | Shape positioning, size, wrapping, and rotation (see below) |
children | SectionChild[] | Body content — paragraphs, tables, etc. (anything a section accepts) |
| paragraph properties | various | Border, shading, and other ParagraphOptions (except style/children) |
VmlShapeStyle
Controls the floating shape's layout. Lengths accept a number (points), a UniversalMeasure string ("2in", "5cm"), a percentage, or "auto".
| Property | Type | Description |
|---|---|---|
width | LengthUnit | Containing-block width (required) |
height | LengthUnit | Containing-block height |
left, top | LengthUnit | Block position |
marginLeft/Right/Top/Bottom | LengthUnit | Margins relative to the shape anchor |
position | "static" | "absolute" | "relative" | Positioning scheme |
positionHorizontal | "absolute" | "left" | "center" | "right" | "inside" | "outside" | Horizontal anchor |
positionHorizontalRelative | "margin" | "page" | "text" | "char" | Horizontal anchor reference |
positionVertical | "absolute" | "left" | "center" | "right" | "inside" | "outside" | Vertical anchor |
positionVerticalRelative | "margin" | "page" | "text" | "char" | Vertical anchor reference |
wrapStyle | "square" | "none" | Text wrapping mode |
wrapDistanceTop/Bottom/Left/Right | number | Distance (pt) from shape to wrapping text |
rotation | number | Rotation in degrees |
flip | "x" | "y" | "xy" | "yx" | Orientation flip |
visibility | "hidden" | "inherit" | Display state |
zIndex | "auto" | number | Overlap order |
Content
children accepts the same section children as a document body — paragraphs, tables, even other text boxes — so a text box can hold richly formatted content:
{
textbox: {
style: { width: "3in", height: "2in" },
children: [
{ paragraph: { children: [{ text: "Title", bold: true, size: 28 }] } },
{ paragraph: { children: ["Supporting paragraph inside the box."] } },
],
},
}