We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Is there any func to get group shape in Word and export it to image?

Hi, I have a word, some group object in files. I want to replace this group to image, this image is convert by this group. Is there any sample code? thanks.

@ZZZ21321 Sure, you can use ShapeRenderer class to render group shape to image. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

// Get the first groupshape in the document.
GroupShape gs = (GroupShape)doc.GetChild(NodeType.GroupShape, 0, true);

// Save group shape as an image.
gs.GetShapeRenderer().Save(@"C:\Temp\gs.png", new ImageSaveOptions(SaveFormat.Png));

Thanks. So how to replace group with this saved image?

@ZZZ21321 You can use code like this to achieve this:

Document doc = new Document("C:\\Temp\\in.docx");

// Get group shape.
GroupShape group = (GroupShape)doc.GetChild(NodeType.GroupShape, 0, true);

// Render the chart to image and save the result into a stream.
MemoryStream groupImageStream = new MemoryStream();
group.GetShapeRenderer().Save(groupImageStream, new ImageSaveOptions(SaveFormat.Png));

// Crete a shape with chart image and insert it after the chart shape.
Shape imageShape = new Shape(doc, ShapeType.Image);
imageShape.ImageData.ImageBytes = groupImageStream.ToArray();
imageShape.Width = group.Width;
imageShape.Height = group.Height;
// There might be other shape properties that you need to set, like wrapping or absolute position.
// ...........

group.ParentNode.InsertAfter(imageShape, group);
// Remove chart shape.