Hi there,
I am evaluating aspose and need it to save groupshapes from RTF files to images.
I have the framework code
NodeCollection shapes = mDocument.GetChildNodes(NodeType.GroupShape, true, false);
int imageIndex = 0;
foreach(GroupShape shape in shapes)
{
foreach(Shape childShape in shape.ChildNodes)
{
// need to save the groupshape somehow
}
imageIndex++;
}
But have no idea how to extract the groupShape as there is no save method.
Could someone kindly help me out? Otherwise I’m afraid we won’t be able to purchase.
Regards
Simon
Thank you for your interest in Aspose.Words. Unfortunately, currently there is no way to render group shape separately to an image. There is the issue #4173 in our defect database regarding this.
Issue #4173 - Support rendering of shapes (separately from all document)
I will notify you as soon as this feature is supported.
Best regards.
Thanks for the info.
I guess I’m clutching at straws but I’m not bothered about keeping the integrity of the group shape and would be happy to convert it to a single shape and then export that if that’s any use.
Regards
Simon
Rendering of shapes means, that you will be able to convert a shape to a raster image. In this case, you will be able to use the image anywhere you need. Currently, you can convert only a particular page to an image.
Could you please attach a document that contains group shape you would like to convert to an image? I will try to create a workaround for you. I would like to try to import a shape to an empty document and then convert this document to image. You can try to achieve this on your side.
Best regards.
Hi Alexey,
I’ve attached a very simple document - I need to name the image with the details to the left, namely
NCSPM SPMEV50 EV1, so the filename will be NCSPMSPMEV50EV1.jpg - we might change this but it’s a good start. There will be several group shapes per file normally.
Good luck!
Regards
Simon
Thank you for additional information. Here is code I mentioned earlier.
// Open document
Document doc = new Document(@"Test165\NCSPM.RTF");
// Get collection of group shapes
NodeCollection shapes = doc.GetChildNodes(NodeType.GroupShape, true);
int shapeIdx = 0;
// Loop through all group shapes
foreach(GroupShape shape in shapes)
{
// Create an empty document
Document tempDoc = new Document();
// Setup margins of the document and pagesize
PageSetup ps = tempDoc.FirstSection.PageSetup;
ps.LeftMargin = 0;
ps.RightMargin = 0;
ps.TopMargin = 0;
ps.BottomMargin = 0;
// page size should be the same as image size
ps.PageHeight = shape.Height;
ps.PageWidth = shape.Width;
// Impost shape the the tmp document
GroupShape tempShape = (GroupShape) tempDoc.ImportNode(shape, true, ImportFormatMode.KeepSourceFormatting);
tempShape.WrapType = WrapType.Inline;
// Insert shape into the docuemnt
tempDoc.FirstSection.Body.FirstParagraph.AppendChild(tempShape);
// Save tmp document as an image
tempDoc.SaveToImage(0, 1, string.Format(@"Test165\out_{0}.jpg", shapeIdx++), null);
}
Works a treat - I’ve changed it to PNG as the quality is much better but essentially a good workaround. Thanks.
I’ve got to get a development estimate and capital projection documented and approved before we can go ahead, but certainly that does everything we need for the time being.
Thanks for your help
Simon