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

Free Support Forum - aspose.com

Slides vs Words Implementation

I am working on a project that involves adding charts to both Word DOCs and PowerPoint PPTs. I implemented the DOC version using code similar to:

MemoryStream imageMs = new MemoryStream();
chart.Save(imageMs, imageFormat);

I then went to code the “equivalent” for Slides, and I thought it would be:

MemoryStream imageMs = new MemoryStream();
chart.Save(imageMs, imageFormat);
Aspose.Slides.Picture oPicture = new Picture(oPresentation, imageMs);
oFrame.PictureId = oPresentation.Pictures.Add(oPicture);

However, this caused an exception. The issue appears to be that after the “chart.Save”, the stream is left at the “end”. If I add the line:
imageMs.Position = 0;
before the “new Picture”, then everything works fine.

So, it appears to be that when chart.Save() is called, the position of the stream is left at the end. When the constructor of Picture is called and it attempts to get the data from the stream, it does not “reset” the stream position, so it fails. Whereas in Words, the “SetImage()” method must reset the stream position.

I don’t know whether this would be considered a bug, and I wasn’t sure whether I should post this to the Slides, Words, or Reports forums, but it seems inconsistent. At least there should be something to document whether the stream position needs to be reset or whether the “consuming” method does it for you.

Hi Bruce,

Thanks for your interest in Aspose.Slides.

Yes, there is a difference of handling image streams between Aspose.Words and Aspose.Slides as identified by you. However, since it is a matter of consistency between the two products, it has not been reported as a bug. Instead, this issue has been reported as an enhancement with issue id 13963 on our Issue Tracking System. This thread has been linked with the issue so that you can be updated here as soon as there is progress on this issue.

Thanks and Best Regards