DocumentBuilderInsertShape(ShapeType, RelativeHorizontalPosition, Double, RelativeVerticalPosition, Double, Double, Double, WrapType) Method

Inserts free-floating shape with specified position, size and text wrap type.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0


public Shape InsertShape(
	ShapeType shapeType,
	RelativeHorizontalPosition horzPos,
	double left,
	RelativeVerticalPosition vertPos,
	double top,
	double width,
	double height,
	WrapType wrapType


Type: Aspose.Words.DrawingShapeType
The shape type to insert into the document
Type: Aspose.Words.DrawingRelativeHorizontalPosition
Specifies where the horizontal distance to the shape is measured from.
Type: SystemDouble
Distance in points from the origin to the left side of the shape.
Type: Aspose.Words.DrawingRelativeVerticalPosition
Specifies where the vertical distance to the shape is measured from.
Type: SystemDouble
Distance in points from the origin to the top side of the shape.
Type: SystemDouble
The width of the shape in points.
Type: SystemDouble
The width of the shape in points.
Type: Aspose.Words.DrawingWrapType
Specifies how to wrap text around the shape.

Return Value

Type: Shape
The shape node that was inserted.


Shows how to insert DML shapes into the document using a document builder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// There are two ways of shape insertion
// These methods allow inserting DML shape into the document model
// Document must be saved in the format, which supports DML shapes, otherwise, such nodes will be converted
// to VML shape, while document saving

// 1. Free-floating shape insertion
Shape freeFloatingShape = builder.InsertShape(ShapeType.TopCornersRounded, RelativeHorizontalPosition.Page, 100, RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);
freeFloatingShape.Rotation = 30.0;
// 2. Inline shape insertion
Shape inlineShape = builder.InsertShape(ShapeType.DiagonalCornersRounded, 50, 50);
inlineShape.Rotation = 30.0;

// If you need to create "NonPrimitive" shapes, like SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
// TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, DiagonalCornersRounded
// please save the document with "Strict" or "Transitional" compliance which allows saving shape as DML
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;

doc.Save(ArtifactsDir + "Shape.ShapeInsertion.docx", saveOptions);

See Also