InsertShape

InsertShape(ShapeType, double, double)

Inserts inline shape with specified type and size.

public Shape InsertShape(ShapeType shapeType, double width, double height)
ParameterTypeDescription
shapeTypeShapeTypeThe shape type to insert into the document.
widthDoubleThe width of the shape in points.
heightDoubleThe height of the shape in points.

Return Value

The shape node that was inserted.

Examples

Shows how to insert DML shapes into a document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Below are two wrapping types that shapes may have.
// 1 -  Floating:
builder.InsertShape(ShapeType.TopCornersRounded, RelativeHorizontalPosition.Page, 100,
        RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);

// 2 -  Inline:
builder.InsertShape(ShapeType.DiagonalCornersRounded, 50, 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.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;

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

See Also


InsertShape(ShapeTypeRelativeHorizontalPosition, double, RelativeVerticalPosition, double, double, double, WrapType)

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

public Shape InsertShape(ShapeType shapeType, RelativeHorizontalPosition horzPos, double left, 
    RelativeVerticalPosition vertPos, double top, double width, double height, WrapType wrapType)
ParameterTypeDescription
shapeTypeShapeTypeThe shape type to insert into the document
horzPosRelativeHorizontalPositionSpecifies where the horizontal distance to the shape is measured from.
leftDoubleDistance in points from the origin to the left side of the shape.
vertPosRelativeVerticalPositionSpecifies where the vertical distance to the shape is measured from.
topDoubleDistance in points from the origin to the top side of the shape.
widthDoubleThe width of the shape in points.
heightDoubleThe height of the shape in points.
wrapTypeWrapTypeSpecifies how to wrap text around the shape.

Return Value

The shape node that was inserted.

Examples

Shows how to insert DML shapes into a document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Below are two wrapping types that shapes may have.
// 1 -  Floating:
builder.InsertShape(ShapeType.TopCornersRounded, RelativeHorizontalPosition.Page, 100,
        RelativeVerticalPosition.Page, 100, 50, 50, WrapType.None);

// 2 -  Inline:
builder.InsertShape(ShapeType.DiagonalCornersRounded, 50, 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.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.Docx);
saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;

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

See Also