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

Free Support Forum - aspose.com

Doc to html conversion using steam not formatted correctly

Using the below code I can get a .doc to load into html but when it displays the layout and format do no seam to match the original document. The pages seam to overlap and not conform to the originals width or height. I need to be able to do this without saving files to disk. The app might not have access to write to disk is all cases. It also needs to work for a large variation of documents and layouts if possible.

.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New", Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ } 
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #a31515; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
    background-color: #f4f4f4;
    width: 100%;
    margin: 0em;
.csharpcode .lnum { color: #606060; }
public string GetDocToHtml(string path)
    Aspose.Words.Document doc = new Aspose.Words.Document(path);

    HtmlSaveOptions options = new HtmlSaveOptions();
    options.SaveFormat = SaveFormat.Html;

    HtmlSaveOptionHandler saverHandle = new HtmlSaveOptionHandler();
    options.DocumentPartSavingCallback = saverHandle;
    HandleImageSaving imageSave = new HandleImageSaving();
    options.ImageSavingCallback = imageSave;
    options.ExportImagesAsBase64 = true;

    return doc.ToString(options);

public class HtmlSaveOptionHandler : IDocumentPartSavingCallback
    public void DocumentPartSaving(DocumentPartSavingArgs args)
        args.DocumentPartStream = new MemoryStream();
        args.KeepDocumentPartStreamOpen = true;

public class HandleImageSaving : IImageSavingCallback
    void IImageSavingCallback.ImageSaving(ImageSavingArgs e)
        e.ImageStream = new MemoryStream();
        e.KeepImageStreamOpen = false;

Is there a set of setting I am missing? is it possible to duplicate the original file exactly using only stream or other methods of not writing to files?


Hi Mike,

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

I have attached a couple of the files that will need to be reproduced into html.


Hi Mike,

Thanks for sharing the detail. Please note that MS Word format and HTML formats are quite different so sometimes it’s hard to achieve 100% fidelity. Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting/importing here:

Load in the HTML (.HTML, .XHTML, .MHTML) Format
Save in the HTML (.HTML, .XHTML, .MHTML) Format

We suggest you please save the documents to HtmlFixed file format. Please check HtmlFixedSaveOptions class. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.SaveFormat = SaveFormat.HtmlFixed;
doc.Save(MyDir + "Out.html", options);


Is it possible to use fixed Save and not save to disk. I am attempting to display the .doc in a webpage without having to save a version of it onto the disk.

The ultimate end goal is to be able to display any .doc or .docx the exact same or very similar to the original in a webpage without making any copies anywhere.

Is that possible using the current Words API? or is there a better way than converting to html/fixedhtml to accomplish this task?


Hi Mike,

Thanks for your inquiry. In your case, we suggest you please save the document to HtmlFixed file format. You can save the document to memory stream. Please check following highlighted code snippet. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.SaveFormat = SaveFormat.HtmlFixed;
MemoryStream stream = new MemoryStream();
doc.Save(stream, options);