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

Free Support Forum - aspose.com

Convert Docx file to HTML on fly


I have tried to convert a docx file to html file. I successfully convert the file data into html. But now I need to get the data of the generated HTML without creating the file (on fly). But when I am trying to convert it, I am getting an error “Memory stream is not expandable.”.

Things I have tried,

Aspose.Words.Document doc = new Aspose.Words.Document(@“C:\Users\arkadeepd000\Desktop\1.docx”);
MemoryStream imagesStream = new MemoryStream();
var handleImageSaving = new HandleImageSaving(imagesStream);

HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.Html);
options.ExportImagesAsBase64 = false;
options.PrettyFormat = true;
options.ExportOriginalUrlForLinkedImages = true;
options.ExportRoundtripInformation = false;
options.ImageSavingCallback = handleImageSaving;

using (MemoryStream outStream = new MemoryStream())
doc.Save(outStream, options);
byte[] docBytes = outStream.ToArray();
string result = System.Text.Encoding.UTF8.GetString(docBytes);

public class HandleImageSaving : IImageSavingCallback
public ArrayList ImageStreams;
private MemoryStream m_images;

    public HandleImageSaving(MemoryStream i_images)
        ImageStreams = new ArrayList();
        m_images = i_images;
    void IImageSavingCallback.ImageSaving(ImageSavingArgs args)
        Shape shape = (Shape)args.CurrentShape;
        m_images = new MemoryStream(shape.ImageData.ImageBytes);

        args.ImageStream = m_images;
        args.KeepImageStreamOpen = true;

Need your help to mitigate this issue.


Thanks for your inquiry. Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.