logo
search
Others

How to Insert and Position a Text Box in Word Using Open XML

Steve KSteve K Sep 30, 2026 869 views

Question details

The user needs to programmatically create and accurately position a text box within a Word document using the DocumentFormat.OpenXml library.

How to Insert and Position a Text Box in Word Using Open XML
Product
DocumentFormat.OpenXml
Device & OS
not provided
Scenario
Automating Word document creation or modifying document layouts programmatically via C# and the Open XML SDK.
Observed behavior
A text box must be structured properly within a Drawing element and its placement controlled via specific horizontal and vertical coordinate elements in EMUs.
Before you start

Ensure you have the DocumentFormat.OpenXml SDK installed and that your project includes the necessary references to DocumentFormat.OpenXml and WindowsBase.

Solution 1Recommended

Constructing and Positioning the Text Box via Open XML Elements

Build the text box using Drawing elements and define its exact location utilizing PositionOffset values and English Metric Units (EMUs).

In Open XML, text boxes are not standalone elements but are embedded within a Drawing element. The placement is highly specific and relies on configuring relative coordinate systems instead of absolute page placements.

1
Construct the Text Content

Create the text box content programmatically by instantiating TextBoxContent, Paragraph, Run, and Text elements in your C# code.

2
Wrap in a Drawing Element

Place the constructed text box content inside a Drawing element, which handles the graphical rendering within the Word document structure.

3
Configure Positioning Elements

Use HorizontalPosition and VerticalPosition elements to dictate where the text box sits. Apply PositionOffset values to specify the exact coordinates measured in EMUs (English Metric Units).

4
Set the Relative Anchor

Define whether the HorizontalPosition and VerticalPosition are relative to the entire page, the page margins, or a specific paragraph to ensure dynamic documents render correctly.

5
Append to the Document

Append the fully configured Drawing element to the main document body and save the Open XML package.

Constructing and Positioning the Text Box via Open XML Elements
Pro Tip: Because Open XML hierarchies can be complex, the easiest way to generate valid positioning XML is to manually create your ideal text box in Microsoft Word and inspect its underlying code using the Open XML Productivity Tool.
Free Microsoft Office alternative

Easily Insert and Format Text Boxes with WPS Office

While Open XML is powerful for backend automation, managing text box positioning manually is much easier in a fully-featured word processor. WPS Office provides a free, highly compatible alternative to Microsoft Word for seamless document editing.

  1. 1. Open WPS Writer: Launch WPS Office and open your .docx document.
  2. 2. Insert a Text Box: Navigate to the 'Insert' tab on the top ribbon and select 'Text Box'.
  3. 3. Position Visually: Click and drag to draw the text box anywhere on the page, and use the wrapping options to perfectly align it with your text.
Seamlessly compatible with Microsoft Word (.docx) formats and XML structuresEasily drag, drop, and position text boxes visually without codingLightweight architecture ensures fast installation and performanceFree to use with comprehensive document layout and editing tools
microsoft office alternative - wps office

Frequently Asked Questions

What is an EMU in Open XML positioning?

EMU stands for English Metric Unit. It is a coordinate measurement used in Open XML to ensure graphics and drawings render exactly the same across different devices and screens. There are 914,400 EMUs in one inch.

How can I easily find the correct XML for a text box?

You can manually draw and position a text box in Microsoft Word, save the document, and open it using the Open XML Productivity Tool. Use the tool's 'Reflect Code' feature to automatically generate the C# code needed to recreate that layout.

Can I position a text box relative to a paragraph instead of the page?

Yes. By using the SimplePosition, HorizontalPosition, and VerticalPosition elements, you can define the relative anchor point to be a specific paragraph, margin, or the entire page boundaries.