• 4 minutes to read

The Word Processing Document API allows you to load/save, print and export (PDF) documents containing shapes (drawing objects). The RichEditDocumentServer supports all shape types: from simple lines and rectangles to shapes with advanced effects.


You can perform the following actions with shapes.


The Word Processing Document API does not support using shapes in OpenDocument Text (.odt) documents.

Access a Shape

The ShapeCollection contains Shape objects. Access the collection using the SubDocument.Shapes property. You can retrieve the collection item by its index or name using the array notation. Use the Name property to specify the drawing object's name.

// Access a shape by its index.
Shape myShape = document.Shapes[0];

// Access a shape by its name.
Shape myShape = document.Shapes["Object1"];

Create a Shape

The RichEditDocumentServer provides the following API to create shapes, pictures and text boxes.


The DocumentImageCollection.Append and DocumentImageCollection.Insert methods create images and add them to the ShapeCollection.

// Insert a rectangle at the beginning of the document.
Shape rectangle = richEditDocumentServer1.Document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new RectangleF(300, 200, 500, 300));
// Fill the rectangle with color.
rectangle.Fill.SetSolidFill(Color.FromArgb(0xFF, 0xEE, 0xAD));

// Insert a picture at the end of the document.
richEditDocumentServer1.Document.Shapes.InsertPicture(richEditControl1.Document.Range.End, Image.FromFile("image001.jpg"));

Modify a Shape


Use the Shape.TextWrapping property to specify the text flow around the drawing object. The following properties allow you to define the shape's position within the document.




Places the floating object behind or in front of other shapes.


Positions the object relative to a certain point.



Positions the object relative to the page element.



Defines the page element to which the object position is relative.

The example below uses the Shape.ZOrder property to position a picture behind the specified drawing object and sets the picture's Shape.TextWrapping property to BehindText.


document.LoadDocument("FirstLook.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
Shape myPicture = document.Shapes[1];
myPicture.VerticalAlignment = ShapeVerticalAlignment.Top;
myPicture.ZOrder = document.Shapes[0].ZOrder - 1;
myPicture.TextWrapping = TextWrappingType.BehindText;

Rotate and Resize

Use the RotationAngle property to rotate a shape. The Size property determines the shape's size. Set the ScaleX or ScaleY property to scale the shape horizontally or vertically.

The following code rotates and resizes pictures in the document.


document.LoadDocument("FirstLook.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml);
foreach (Shape s in document.Shapes)
    // Rotate and resize pictures.
    if (s.Type == ShapeType.Picture)
        s.ScaleX = 0.8f;
        s.ScaleY = 0.8f;
        s.RotationAngle = 45;

Format a Shape

Use the following API members to customize a shape's appearance:

  • Shape.Fill - Allows you to specify shape fill options.

  • Shape.Line - Provides access to format settings for a line or shape's border.

  • ShapeLine.Fill - Allows you to specify line fill options.

The example below shows how to create a rectangle and change its border settings.


// Add a rectangle to a document.
Shape rectangle = document.Shapes.InsertShape(document.Range.Start, ShapeGeometryPreset.Rectangle, new RectangleF(300, 200, 500, 300));
// Fill the rectangle with color.
rectangle.Fill.SetSolidFill(Color.FromArgb(0xFF, 0xEE, 0xAD));
// Format the rectangle border.
ShapeLine border = rectangle.Line;
border.Color = Color.FromArgb(0x4D, 0x64, 0x8D);
border.Thickness = 6;
border.JoinType = LineJoinType.Miter;
border.DashType = LineDashType.Solid;
border.CompoundType = LineCompoundType.ThickThin;

Delete a Shape

Use the ShapeCollection.Remove and ShapeCollection.RemoveAt methods to delete drawing objects from a document.

// Remove the first shape from the collection.

You can also delete the range that contains the shape's anchor to remove the drawing object.

See Also