Aspose::Words::DocumentBuilder::InsertShape method

DocumentBuilder::InsertShape(Aspose::Words::Drawing::ShapeType, Aspose::Words::Drawing::RelativeHorizontalPosition, double, Aspose::Words::Drawing::RelativeVerticalPosition, double, double, double, Aspose::Words::Drawing::WrapType) method

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

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertShape(Aspose::Words::Drawing::ShapeType shapeType, Aspose::Words::Drawing::RelativeHorizontalPosition horzPos, double left, Aspose::Words::Drawing::RelativeVerticalPosition vertPos, double top, double width, double height, Aspose::Words::Drawing::WrapType wrapType)
ParameterTypeDescription
shapeTypeAspose::Words::Drawing::ShapeTypeThe shape type to insert into the document
horzPosAspose::Words::Drawing::RelativeHorizontalPositionSpecifies where the horizontal distance to the shape is measured from.
leftdoubleDistance in points from the origin to the left side of the shape.
vertPosAspose::Words::Drawing::RelativeVerticalPositionSpecifies 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.
wrapTypeAspose::Words::Drawing::WrapTypeSpecifies how to wrap text around the shape.

ReturnValue

The shape node that was inserted.

Examples

Shows how to insert DML shapes into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
auto saveOptions = MakeObject<OoxmlSaveOptions>(SaveFormat::Docx);
saveOptions->set_Compliance(OoxmlCompliance::Iso29500_2008_Transitional);

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

See Also

DocumentBuilder::InsertShape(Aspose::Words::Drawing::ShapeType, double, double) method

Inserts inline shape with specified type and size.

System::SharedPtr<Aspose::Words::Drawing::Shape> Aspose::Words::DocumentBuilder::InsertShape(Aspose::Words::Drawing::ShapeType shapeType, double width, double height)
ParameterTypeDescription
shapeTypeAspose::Words::Drawing::ShapeTypeThe shape type to insert into the document.
widthdoubleThe width of the shape in points.
heightdoubleThe height of the shape in points.

ReturnValue

The shape node that was inserted.

Examples

Shows how to insert DML shapes into a document.

auto doc = MakeObject<Document>();
auto builder = MakeObject<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.
auto saveOptions = MakeObject<OoxmlSaveOptions>(SaveFormat::Docx);
saveOptions->set_Compliance(OoxmlCompliance::Iso29500_2008_Transitional);

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

See Also