Converting Docx to HTML not showing images

Hi,

I m trying to convert a Doc file to HTML in Mailmerge and it is working fine except Images are not converting on newly created HTML page.

While Converting Docx to PDF is converting iamge as well but not in case of converting to HTML

Here is the code

public ActionResult PreviewTemplate()
{
    try
    {
        string newFullPath = "C:\mergefiles\Letter - Logo.html";

        Aspose.Words.Document doc = new Aspose.Words.Document("C:\mergefiles\Letter - Logo.docx");

        var htmlOptions = new HtmlSaveOptions();
        htmlOptions.ExportXhtmlTransitional = true;
        htmlOptions.ImagesFolder = "file:///C:/Temp/attachments";
        htmlOptions.ImagesFolderAlias = "/attachment";
        htmlOptions.SaveFormat = SaveFormat.Html;
        doc.Save(newFullPath, htmlOptions);

        return File(newFullPath, "text/xml");
    }

Please guide…

Hi,

Thanks for your inquiry. Please use the following code to fix this problem (Please also see HtmlSaveOptions.ExportHeadersFootersMode property):

Document doc = new Document(MyDir + @"Letter±+Logo.doc");
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstPageHeaderFooterPerSection;
doc.Save(MyDir + @"16.1.0.html", opts);

Hope, this helps.

Best regards,

Hi,

Thanks for you reply.

But the option available to me is 'FirstSectionHeaderLastSectionFooter’

and using this not working…

string myDir = "C:\\mergefiles\\";
Aspose.Words.Document doc = new Aspose.Words.Document(myDir + @"Letter - Logo.docx");

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstSectionHeaderLastSectionFooter;
doc.Save(myDir + @"Letter - Logo.html", opts);

Please suggest

Hi,

Thanks for your inquiry. You can use HtmlSaveOptions.ExportHeadersFootersMode property specify how headers and footers are output to HTML, MHTML or EPUB. Default value is PerSection for HTML/MHTML and None for EPUB.

It is hard to meaningfully output headers and footers to HTML because HTML is not paginated. When this property is PerSection, Aspose.Words exports only primary headers and footers at the beginning and the end of each section. When it is FirstSectionHeaderLastSectionFooter only first primary header and the last primary footer (including linked to previous) are exported. You can disable export of headers and footers altogether by setting this property to None.

In your case you need to export first page header and footer to HTML. Hope, this helps.

Best regards,

Hi,

Setting HtmlSaveOptions.ExportHeadersFootersMode to NONE or PerSection

But nothing helped.

Moreover i m getting one more issue. ‘Regular Text’ Type merge fields when converted to HTML showing text boxes (converted to following html)

Please see the attached Document used to convert to HTML
Please suggest.

Hi,

Thanks for your inquiry. In your “Letter - Logo.doc document”, there is one “Primary Header” and one “First Page Header”. The picture is contained inside first page header. Now, you need to run the following code to be able to export it to HTML (see attached 16.1.0.zip):

Document doc = new Document(MyDir + @"Letter±+Logo.doc");
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html);
opts.ExportHeadersFootersMode = ExportHeadersFootersMode.FirstPageHeaderFooterPerSection;
doc.Save(MyDir + @"16.1.0.html", opts);

We can offer you another solution i.e. converting the Word document to the HTML format using absolutely positioned elements (HtmlFixed) produces the expected output. Here is how you can use HtmlFixedSaveOptions to get output in HtmlFixed save format and perhaps, you will be satisfied with HTML Fixed format (see attached 16.1.0-HtmlFixed.zip).

Document doc = new Document(MyDir + @"Letter+-+Logo.doc");
HtmlFixedSaveOptions option = new HtmlFixedSaveOptions();
option.SaveFormat = SaveFormat.HtmlFixed;
doc.Save(MyDir + @"16.1.0-HtmlFixed.html", option);

Hope, this helps.

Best regards,

Using

HtmlFixedSaveOptions option = new HtmlFixedSaveOptions();
option.SaveFormat = SaveFormat.HtmlFixed;

makes it working fine, thanks a lot

HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.HTML);
opts.setExportImagesAsBase64(true);
Document doc = new Document("Synopsis.docx");
doc.save("Ask.html", opts);

It is not converting my .docx file properly to html. .docx file is attached in .zip file.
Synopsis.zip (16.2 KB)

@Anurag16jun,

We were also not able to get correct output when saving this ‘Synopsis.docx’ document to plain HTML format by using MS Word 2016 on our end. So, this seems to be an expected behavior. Instead, we suggest you please try saving to HtmlFixed format. Please see aw-msw-outputs.zip (149.0 KB)