How to convert docx to html using aspose in mvc c#

Hi all,

I am using aspose 22.10.0 , i am converting docx to html template i am displaying in the html template, when document contains Bullet and numbering and page reference instead the bullet and page reference its showing ??? multiple times ,

below is my code and attached document && error screen shot for your reference


source. (2).docx (13.5 KB)

Document docMaster = new Document(System.IO.Path.Combine(storagePath, outputDetails.Result.Item2.ModifiedMasterFileName));
FindReplaceOptions opt = new FindReplaceOptions();
opt.ReplacingCallback = new QuoteReplacingCallback();
docMaster.Range.Replace(new Regex("[“”‘’–]"), "", opt);
MemoryStream stream = new MemoryStream();
HtmlSaveOptions options2 = new HtmlSaveOptions(SaveFormat.Html)
{
    ExportTextInputFormFieldAsText = true,
    ExportImagesAsBase64 = true,
    CssStyleSheetType = CssStyleSheetType.Embedded,
    ExportFontsAsBase64 = true,
    ExportPageMargins = true,
    ExportShapesAsSvg = true,
    HtmlVersion = HtmlVersion.Html5,
    UseHighQualityRendering = true,
    ExportTocPageNumbers = true,
    ExportRelativeFontSize = true,
    ExportDocumentProperties = true,
};

options2.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;

docMaster.Save(stream, options2);
var html = Encoding.ASCII.GetString(stream.ToArray());
ViewBag.HTML = html.Replace("line-height:107%; font-family:Calibri;", "");

@vengatachalamg4,

I did this code and worked fine.

Note: I am using Aspose Words 23.2

Logic:

public MemoryStream StreamGet()
{
    PartialPath = $@"{prefixPath}\Convertions\HtmlConvertionWithBulletsIssues"; // Location of your input/output files

    LoadLicence(); // Load your License

    var doc = DocumentGet(); // Read your document

    FindReplaceOptions opt = new FindReplaceOptions();
    opt.ReplacingCallback = new HandleReplacing();
    doc.Range.Replace(new Regex("[“”‘’–]"), "", opt);
    HtmlSaveOptions daveOptions = new HtmlSaveOptions(SaveFormat.Html)
    {
        ExportTextInputFormFieldAsText = true,
        ExportImagesAsBase64 = true,
        CssStyleSheetType = CssStyleSheetType.Embedded,
        ExportFontsAsBase64 = true,
        ExportPageMargins = true,
        ExportShapesAsSvg = true,
        HtmlVersion = HtmlVersion.Html5,
        UseHighQualityRendering = true,
        ExportTocPageNumbers = true,
        ExportRelativeFontSize = true,
        ExportDocumentProperties = true,
        Encoding = Encoding.ASCII,
    };

    daveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;

    MemoryStream stream = new MemoryStream();
    doc.Save(stream, daveOptions);

    return stream;
}

Controller:

public class SampleController : Controller
{
    // GET: Sample
    public ActionResult Index()
    {
        var bll = new HtmlConvertionWithBulletsIssuesTest();
        var ms = bll.StreamGet();

        var html = Encoding.ASCII.GetString(ms.ToArray());
        return Content($"<html>{html}</html>");
    }
}

Input
HtmlConvertionWithBulletsIssues_input.docx (13.5 KB)

Output
HtmlConvertionWithBulletsIssues_output.zip (1.6 KB)

Could you share the complete build

@vengatachalamg4,

is a brand new MVC project, with a brand new empty controller.
Then I added a reference to a class library project
Why do you need the build?
What are you looking for?
Do you need to know the framework?

same version i have installed and implement the code , but i getting the error

@vengatachalamg4 Could you please specify what error do you get when use the provided code? Do you see the same problem as described in your initial post?