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

Free Support Forum - aspose.com

Headers and footers are lost when document is saved to HTML using .NET


We have an issue where some document headers and footers are not saved when we open a word doc (docx or rtf) and save as html.
We have found that on the page after we have a section break that asserts either Portrait or Landscape, the headers and footers are not included in html.
We can provide the docx input and html output if required, and the c# code (using Aspose Words version 20.5) we are using is as follows (our live code is more complex, but it boils down to this):

LoadOptions docxLoadOptions = new LoadOptions();
docxLoadOptions.LoadFormat = LoadFormat.Docx;
Document docTest = new Document(testDocXPath, docxLoadOptions);
HtmlSaveOptions HTMLTestoptions = new HtmlSaveOptions(SaveFormat.Html);
docTest.Save(testHtmlPath, HTMLTestoptions);

Is this a known issue in Aspose or is there some other way that we can save the html so that all the docx headers are included?



You are facing the expected behavior of Aspose.Words. The HtmlSaveOptions.ExportHeadersFootersMode property is used to specify how headers and footers are output to HTML. By default, its value is PerSection for HTML.

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.

Moreover, you can save document to HtmlFixed to get the all headers and footers in output document. Hope this helps you.

1 Like

Hi Tahir,

Thanks for the info. HtmlFixed looks to be exactly what we need :slightly_smiling_face:



Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.