简体   繁体   中英

How get images from .docx to stream with Aspose.Words

Task is to replace disk operations with streams. When .docx saved to disk - works perfectly. Tried to change using streams.

Have following code:

            var options = new HtmlSaveOptions(SaveFormat.Html)
            {
                ImageSavingCallback = new HandleImageSaving()
            };

            Stream stream = new MemoryStream();
            doc.Save(stream, options);
            stream.Position = 0;

        public class HandleImageSaving : IImageSavingCallback
        {
            void IImageSavingCallback.ImageSaving(ImageSavingArgs e)
            {
                // here e.IsImageAvailable == true 
                // but e.ImageStream == null
            }
        }

On doc.Save() it goes callback where imagestream for image is empty - but images exist in word document.

Are there any ideas ?

e.ImageStream allows you to specify the stream where image will be saved. If this property is null, it means image will be saved to disk and not to a stream. You can pass a stream object to this property and image will be saved to that stream object eg

Stream imageStream = new MemoryStream();
e.ImageStream = imageStream;

This will save the image to imageStream object after the ImageSaving is called.

I work as developer evangelist at Aspose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM