Image and page number is missing in header and footer for pages

when there is an image in the header, after converting from word to html , the image is missing in header

@athulcp3 It is hard to meaningfully output headers and footers to HTML because HTML is not paginated. By default Aspose.Words exports only primary headers/footers of the document per section when saving to HTML. In your case, probably, there is first page header, so it is not exported to HTML. You can try changing ExportHeadersFootersMode to ExportHeadersFootersMode.FIRST_PAGE_HEADER_FOOTER_PER_SECTION to preserve the first section the first page header:

Document doc = new Document("C:\\Temp\\in.docx");
HtmlSaveOptions opt = new HtmlSaveOptions();
opt.setExportHeadersFootersMode(ExportHeadersFootersMode.FIRST_PAGE_HEADER_FOOTER_PER_SECTION);
doc.save("C:\\Temp\\out.html", opt);

You should note, however, that HTML documents and MS Word documents object models are quite different and it is not always possible to provide 100% fidelity after conversion one format to another.


If the output HTML is for viewing purposes, i.e. it is not supposed to be edited or processed, you can consider using HtmlFixed format. In this case the output should look exactly the same as it looks in MS Word:

Document doc = new Document("C:\\temp\\in.docx");
HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
opt.setExportEmbeddedCss(true);
opt.setExportEmbeddedFonts(true);
opt.setExportEmbeddedImages(true);
opt.setExportEmbeddedSvg(true);
doc.save("C:\\Temp\\out.html", opt);

HtmlFixed format is designed to preserve original document layout for viewing purposes. So if your goal is to display the HTML on page, then this format can be considered as an alternative. But unfortunately, it does not support roundtrip to DOCX at all.

is there any way to retain headers and footer in each page. I meant header and footer per page.

@athulcp3 You can either use HtmlFixed format as suggested above or split the document into pages using Document.extractPages method.

why header and footer is missing in web layout mode

@athulcp3 Headers and footers are not shown in Web mode in MS Word because in Web Mode document is not paginated and as it was mentioned above there is no meaningfully way to display headers and footers in this mode. The same way as to output them to HTML.

Is there any way to select mode while converting to html. That is if we can use PrintLayout mode while converting docx to html

@athulcp3 You can use HtmlFixed format as suggested above. In this mode HTML looks exactly as it look in print layout in MS Word.

Still headers and footers are not coming for my all the pages, After using Document.extractPages

I have a document which has 8 pages and which has header and footer. When i tried to convert the docx to html using aspose the header and footer is missing. Only the first page have the header and footer

@alexey.noskov Document.extractPages didn’t work for me. Still headers and footers are missing.

@athulcp3 Could you please attach your document here? With this simple code I can’t reproduce the issue:

Document doc = new Document("input.docx");
for (int i = 0; i < doc.getPageCount(); i++) {
    Document htmlDoc = doc.extractPages(i, 1);
    HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
    opt.setExportEmbeddedCss(true);
    opt.setExportEmbeddedFonts(true);
    opt.setExportEmbeddedImages(true);
    opt.setExportEmbeddedSvg(true);
    htmlDoc.save(String.format("out_%d.html", i), opt);
}

After using HtmlFixedSaveOptions i am not able to edit the document. I guess it is used for only read. can you please provide some alternative method

@athulcp3 Answered in another post

Using above code able to convert the document to html correctly, but if we again convert the converted html to docx/pdf format ,contents are moved to new page and aligned incorrectly.

@athulcp3 Please note that MS Word 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.

Is this the same document you shared in another post?