How to Insert and Position a Text Box in Word Using Open XML
Question details
The user needs to programmatically create and accurately position a text box within a Word document using the DocumentFormat.OpenXml library.

- 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.
Ensure you have the DocumentFormat.OpenXml SDK installed and that your project includes the necessary references to DocumentFormat.OpenXml and WindowsBase.
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.
Create the text box content programmatically by instantiating TextBoxContent, Paragraph, Run, and Text elements in your C# code.
Place the constructed text box content inside a Drawing element, which handles the graphical rendering within the Word document structure.
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).
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.
Append the fully configured Drawing element to the main document body and save the Open XML package.

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. Open WPS Writer: Launch WPS Office and open your .docx document.
- 2. Insert a Text Box: Navigate to the 'Insert' tab on the top ribbon and select 'Text Box'.
- 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.

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.




