How to Add Group Shape into a Word Document
Sometimes you need to add a group shape into a Word document. Such a group shape consists of multiple shapes.
In Microsoft Word, you can quickly add a group shape using the Group command/button. An individual shape in a group can be moved separately.
In Aspose.Words it is very easy to add a group shape using the GroupShape class. Shape is created separately using the Shape class and then added to the GroupShape object using the AppendChild method.
The following code example shows how to add a group shape into a Word document:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); | |
Document doc = new Document(); | |
doc.EnsureMinimum(); | |
GroupShape gs = new GroupShape(doc); | |
Shape shape = new Shape(doc, Drawing.ShapeType.AccentBorderCallout1); | |
shape.Width = 100; | |
shape.Height = 100; | |
gs.AppendChild(shape); | |
Shape shape1 = new Shape(doc, Drawing.ShapeType.ActionButtonBeginning); | |
shape1.Left = 100; | |
shape1.Width = 100; | |
shape1.Height = 200; | |
gs.AppendChild(shape1); | |
gs.Width = 200; | |
gs.Height = 200; | |
gs.CoordSize = new System.Drawing.Size(200, 200); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
builder.InsertNode(gs); | |
dataDir = dataDir + "groupshape-doc_out.doc"; | |
// Save the document to disk. | |
doc.Save(dataDir); |
Below are some of the Shape
types supported in Aspose.Words:
- Rectangle
- RoundRectangle
- RoundRectangle
- Ellipse
- Diamond
- Triangle
- RightTriangle
- Parallelogram
- Trapezoid
- Hexagon
- Octagon
For complete list, please check the ShapeType class.