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

Free Support Forum - aspose.com

Urgent!Shapes.ImageData.SetImage not working

I am using below code to set image for an existing shape in word document. However image is not rendering in generated pdf. Please help if I am missing anything. Though I am able to see bytes in oshape.Imagedata.Imagebytes, but still image is not rendering.

Node oNode = GetNode(doc.GetChildNodes(NodeType.Shape, true), "Charts");
Shape oshape = (Shape)oNode;
if (oshape.CanHaveImage)

We use Doc.Save("c:\working\abc.pdf",Aspose.Words.SaveFormat.Pdf)

Hi Hetal,
Thanks for your inquiry. The ImageData.SetImage method is now obsolete. Please use the ImageData.ImageBytes property to set an image as shown in following code snippet. ImageData.ImageBytes property gets or sets the raw bytes of the image stored in the shape. Setting the value to null or an empty array will remove the image from the shape.
Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.InsertImage("http://www.aspose.com/images/aspose-logo.gif");
shape.ImageData.ImageBytes = System.IO.File.ReadAllBytes(MyDir + "image001.png");
doc.Save(MyDir + "Out.pdf");

Thanks Tahir
It still doesn’t work. I am using an existing shape which is a text box and inserting image in existing shape. In your example you are creating a new shape and then inserting it. I found one surprising behaviour. If I call Shape.GetShaperenderer() method after calling either Shape.ImageData.Images or Shape.ImageData.SetImage(), then image gets rendered in the PDF. However, Image is too small and textbox doesn’t get resized with the size of image.

Hi Hetal,

Thanks for your inquiry. It would be great if you please share your input document here for testing. I will investigate the issue on my side and provide you more information.

In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.8.0) from here: