Working with Shapes
This topic discusses how to work programmatically with shapes using Aspose.Words. The shapes in Aspose.Words represent an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. A Word document can contain one or more different shapes. Shapes of the document are represented by the Shape class.
Inserting Shapes Using Document Builder
You can insert inline shape with specified type and size and free-floating shape with the specified position, size and text wrap type into a document using DocumentBuilder.insert_shape method. The DocumentBuilder.insert_shape method allows inserting DML shape into the document model. The document must be saved in the format, which supports DML shapes, otherwise, such nodes will be converted to VML shape, while document saving. The following code example shows how to insert these types of shapes into the document.
Set Aspect Ratio Locked
Set Shape Layout In Cell
Create Snip Corner Rectangle
You can create a snip corner rectangle using Aspose.Words. The shape types are SINGLE_CORNER_SNIPPED, TOP_CORNERS_SNIPPED, DIAGONAL_CORNERS_SNIPPED, TOP_CORNERS_ONE_ROUNDED_ONE_SNIPPED, SINGLE_CORNER_ROUNDED, TOP_CORNERS_ROUNDED, and DIAGONAL_CORNERS_ROUNDED. The DML shape is created using DocumentBuilder.insert_shape method with these shape types. These types cannot be used to create VML shapes. Attempt to create shape by using the public constructor of the Shape class raises the “NotSupportedException” exception. The following code example shows how to insert these type of shapes into the document.
Get Actual Shape Bounds Points
Specify Vertical Anchor
Detect SmartArt Shape
Insert Horizontal Rule into Document
The code example given below demonstrates how to insert horizontal rule shape into a document using DocumentBuilder.insert_horizontal_rule method.
Aspose.Words API provides Shape.horizontal_rule_format property to access the properties of the horizontal rule shape. The HorizontalRuleFormat class exposes basic properties like height, color, no_shade etc. for the formatting of a horizontal rule. The following code example demonstrates how to set HorizontalRuleFormat.
Insert OLE Object as an Icon
Aspose.Words API provides Shape.insert_ole_object_as_icon function to insert an embedded or linked OLE object as an icon into the document. This function allows specifying the icon file and the caption. The OLE object type shall be detected using the file extension. The following code example demonstrates how to set insert OLE object as an Icon into the document.
Import Shapes with Math XML as Shapes into DOM
You can use LoadOptions.convert_shape_to_office_math property to convert the shapes with EquationXML to Office Math objects. The default value of this property corresponds to MS Word behavior i.e. shapes with equation XML are not converted to Office math objects.