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

Free Support Forum - aspose.com

Getting Native Shapes from Word as Image

[Using Aspose.Words.dll 13.5.0.0]

Is it possible to get the native Shapes generated from Word as images via Aspose?

Let me explain what I'm trying to do...
I have a dummy document with a Flowchart: Document shape in it. When opening this document programatically with Aspose, then saving it to disk as HTML named "Dummy.html", I get an image associated with that file saved on disk as "Dummy.001.png" and the resulting html looks fine. So I know your code is able to read that shape and translate it to an image. I want to be able to get that raw image too in the code behind while processing the document.

I can successfully intercept the Node's image for those attached to the document, but not the raw Word Shapes. To do this so far I have:

//node is just some node off a random paragraph
if (node.NodeType == NodeType.Shape)//This returns true
{
Aspose.Words.Drawing.Shape shape = (Aspose.Words.Drawing.Shape)node; // I can also cast this as a ShapeBase instead
if (shape.HasImage)//This returns false for Word native shapes!
{
//I do this for embedded images, works great!
byte[] inputBytes = shape.ImageData.ImageBytes;
MemoryStream memoryStream = new MemoryStream(inputBytes);
System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
//Etc etc....
}
else if (shape.CanHaveImage)//This returns true. What governs what this returns?
{
//Execute my code here?
}
}
....

As I said this works just fine for images actually uploaded into the document that are non-native. Hence my use of the shape.HasImage. See the code in red for how I use that.

However, I want to be able to grab the native Shapes that Word uses in the same manner. I don't care if its a byte array, a memory stream, or Image, I need some way of getting that raw image back.

I can see limited information about the shape object if I cast the node differently, (ShapeBase)(node).ShapeType, this gets me the related shape type from Word (FlowChartDocument - As seen in your documentation http://www.aspose.com/docs/display/wordsnet/ShapeType+Enumeration) but from all points I've tried to look at, I'm unable to get any kind of image data. I can even see the text inside the Shape "Hello World"! But from everything I've tried, I cannot get that Shape.

Hi Philip,


Thanks for your inquiry and sorry for the delayed response. Sure, you can extract all images found in the document and export them to an external location e.g to disk. This is a simple task when extracting images as the Aspose.Words API already provides members for extracting and saving image data. Please refer to the following section of the documentation which outlines everything you need to know:
http://www.aspose.com/docs/display/wordsnet/How+to++Render+Shapes+Separately+from+a+Document

Please let me know if I can be of any further assistance.

Best regards,