insert_shape method
Contents
[
Hide
]insert_shape(shape_type, width, height)
Inserts inline shape with specified type and size.
def insert_shape(self, shape_type: aspose.words.drawing.ShapeType, width: float, height: float):
...
Parameter | Type | Description |
---|---|---|
shape_type | ShapeType | The shape type to insert into the document. |
width | float | The width of the shape in points. |
height | float | The height of the shape in points. |
Returns
The shape node that was inserted.
insert_shape(shape_type, horz_pos, left, vert_pos, top, width, height, wrap_type)
Inserts free-floating shape with specified position, size and text wrap type.
def insert_shape(self, shape_type: aspose.words.drawing.ShapeType, horz_pos: aspose.words.drawing.RelativeHorizontalPosition, left: float, vert_pos: aspose.words.drawing.RelativeVerticalPosition, top: float, width: float, height: float, wrap_type: aspose.words.drawing.WrapType):
...
Parameter | Type | Description |
---|---|---|
shape_type | ShapeType | The shape type to insert into the document |
horz_pos | RelativeHorizontalPosition | Specifies where the horizontal distance to the shape is measured from. |
left | float | Distance in points from the origin to the left side of the shape. |
vert_pos | RelativeVerticalPosition | Specifies where the vertical distance to the shape is measured from. |
top | float | Distance in points from the origin to the top side of the shape. |
width | float | The width of the shape in points. |
height | float | The height of the shape in points. |
wrap_type | WrapType | Specifies how to wrap text around the shape. |
Returns
The shape node that was inserted.
Examples
Shows how to insert DML shapes into a document.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Below are two wrapping types that shapes may have.
# 1 - Floating:
builder.insert_shape(shape_type=aw.drawing.ShapeType.TOP_CORNERS_ROUNDED, horz_pos=aw.drawing.RelativeHorizontalPosition.PAGE, left=100, vert_pos=aw.drawing.RelativeVerticalPosition.PAGE, top=100, width=50, height=50, wrap_type=aw.drawing.WrapType.NONE)
# 2 - Inline:
builder.insert_shape(shape_type=aw.drawing.ShapeType.DIAGONAL_CORNERS_ROUNDED, width=50, height=50)
# If you need to create "non-primitive" shapes, such as SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,
# TopCornersOneRoundedOneSnipped, SingleCornerRounded, TopCornersRounded, or DiagonalCornersRounded,
# then save the document with "Strict" or "Transitional" compliance, which allows saving shape as DML.
save_options = aw.saving.OoxmlSaveOptions(aw.SaveFormat.DOCX)
save_options.compliance = aw.saving.OoxmlCompliance.ISO29500_2008_TRANSITIONAL
doc.save(file_name=ARTIFACTS_DIR + 'Shape.ShapeInsertion.docx', save_options=save_options)
See Also
- module aspose.words
- class DocumentBuilder