Hi Team,
How do I group multiple shapes in word document using Aspose.Words.
As in attached word file we want to group all shapes in one group and extract as a single image.
Attached sample file for your reference.Manuscript 1.zip (39.5 KB)
Thanks,
Mallikarjun
@mallikarjun.sidveer
You can use the same approach as shown below to insert shapes into GroupShape. Hope this helps you.
Document doc = new Document();
Shape s1 = AddShape(doc, doc.FirstSection.Body.FirstParagraph, ShapeType.TextPlainText, new RectangleF(72, 72, 72, 72), "hello");
Shape s2 = AddShape(doc, doc.FirstSection.Body.FirstParagraph, ShapeType.Line, new RectangleF(144, 144, 72, 0), "");
Shape s3 = AddShape(doc, doc.FirstSection.Body.FirstParagraph, ShapeType.DownArrow, new RectangleF(144, 144, 36, 144), "");
GroupShape gs = new GroupShape(doc);
gs.Width = 72 * 4;
gs.Height = 72 * 4;
gs.CoordSize = new System.Drawing.Size(72 * 4, 72 * 4);
gs.AppendChild(s1);
gs.AppendChild(s2);
gs.AppendChild(s3);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.Writeln();
builder.Writeln();
builder.Writeln();
builder.InsertNode(gs);
doc.Save(MyDir + @"19.7.docx");
public static Shape AddShape(Document doc, Paragraph anchorPara, ShapeType shapeType, RectangleF rectangleF, string text)
{
Shape shape = new Shape(doc, shapeType);
shape.Left = rectangleF.Left;
shape.Top = rectangleF.Top;
shape.Width = rectangleF.Width;
shape.Height = rectangleF.Height;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
shape.WrapType = WrapType.None;
if (!string.IsNullOrEmpty(text))
{
Paragraph para = new Paragraph(doc);
Run run = new Run(doc, text);
para.AppendChild(run);
shape.AppendChild(para);
}
anchorPara.AppendChild(shape);
return shape;
}
Hi @tahir.manzoor
Thanks for your support.
We already have shapes in attached sample document, just we want to group them.
I am trying with below code using the same approach as you mentioned, but its not working.
private void GroupAllShapes(string manuscriptPath)
{
Document doc = new Document(manuscriptPath);
GroupShape gs = new GroupShape(doc);
Node[] shapes = doc.GetChildNodes(NodeType.Shape, true).ToArray();
foreach (Shape s in shapes)
{
gs.ChildNodes.Add(s);
}
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(gs);
doc.Save(manuscriptPath);
}
I am getting below exception:
Cannot insert a Shape into a GroupShape with a different markup language.
at Aspose.Words.Drawing.GroupShape.r3ka8zscesabkstb24kjjv9sml9wq7pw (Node )
at Aspose.Words.CompositeNode.(Node , Node , Boolean )
@mallikarjun.sidveer
We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18944. You will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.
@tahir.manzoor
Thanks for your replay.
Any update on this?
@mallikarjun.sidveer
Unfortunately, there is no update available on this issue at the moment. We will inform you via this forum thread once this issue is resolved. Thanks for your patience.
@tahir.manzoor
Hi Tahir,
Any updates on issue WORDSNET-18944 still status is showing as Analysis Complete.
Thanks,
Mallikarjun
@mallikarjun.sidveer
We try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.
You reported this issue in free support forum and it will be treated with normal priority. However, we will inform you via this forum thread once there is an update available on it.
Thanks for your patience and understanding.
Hi Tahir,
Any updates on issue WORDSNET-18944 status is showing as Analysis Complete from long time.
Thanks,
Mallikarjun
@mallikarjun.sidveer
Unfortunately, your issue is not resolved yet. We have completed the analysis of this issue but I am afraid, there is no ETA available at the moment. We will inform you via this thread as soon as this issue will be resolved in future or any estimates may be available.
We apologize for your inconvenience.
@mallikarjun.sidveer
There is no update available on this issue at the moment.
You reported this issue in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies