Retain Headers in word to mhtml transition

Hi,
while converting a word document to mhtml/html , i am able to view only first page header and last page footer. is their any work around so that we can have headers of all of the pages displayed [just like pdf but not want to use pdf]. Any help will be truly appreciated.

Thanks in advance
Suhas

Hi Suhas,

Thanks for your inquiry.

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

[C#]

public ExportHeadersFootersMode ExportHeadersFootersMode {get; set;}

Remarks:
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.

Example:
Demonstrates how to disable the export of headers and footers when saving to HTML based formats.

[C#]

Document doc = new Document(MyDir + "HeaderFooter.RemoveFooters.doc");
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Html);
saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.None; // Disables exporting headers and footers.
doc.Save(MyDir + "HeaderFooter.DisableHeadersFooters Out.html", saveOptions);

Best Regards,

It has been after long time, but still I am facing the same problem.
I want to achieve following.

  • I have MS word document of 4 pages (Multiple page doc - Pl. refer docx attached) with headers and footers.
  • Which(word doc) I want to show as web page in ASP.net application.
  • It should display headers and footers of all the 4 pages

I am using following code for Saving word document in Mhtml format.

HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.Mhtml);
saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;
doc.Save(WordDocumentPath, saveOptions);

Issue is: Web page just displays header/footer of first page and last page. It is not displaying headers and footers for all the pages. (Please refer snapshot of Web Page)
Is there any solution/work-around to achieve above requirement?

Hi Suhas,

Thanks for your inquiry. In this case, you may want to save this document in the HTML format using absolutely positioned elements as follows:

Document doc = new Document(@"C:\Temp\HeaderFooterTest - Copy.docx");
doc.Save(@"C:\Temp\out.html", SaveFormat.HtmlFixed);

Please let me know if I can be of any further assistance.

Best regards,

Awais,
I applied the changes as per your suggestion. And found html file with following issues.

  1. Header values are overlapped with each other.
  2. Html file shows Page Footer on the top.

(Please refer attached .png file)
Did you try it at your end? Please let me know where things are going wrong.

Hi Suhas,

Thanks for your inquiry. Please attach your input Word document you’re getting this problem with here for testing. I will investigate the issue on my side and provide you more information.

Best regards,

Awais,
Please find attached word document.
I want to see html document as same as the attached Word Document (Including headers and footers).
-Suhas

Hi Suhas,

Thanks for your inquiry. Unfortunately, I couldn’t observe this content overlapping issue when opening the attached out_13.10.0.html with IEv9, Chrome or FireFox on my side. This html was generated with Aspose.Words for .NET 13.10.0 using the code from my previous post. I would suggest you please upgrade to the latest version from the following link:
https://releases.aspose.com/words/net

I hope, this helps.

Best regards,

Awais,
Coming back to the points which I raised in previous post are as below,
I want to achieve following.

  • I have MS word document of 4 pages (Multiple page doc - Pl. refer docx attached) with headers and footers.
  • Which(word doc) I want to show as web page in ASP.net application.
  • It should display headers and footers of all the 4 pages

As mentioned in above points,
Are you able to generate output - html document - showing whole content of attached word document (including header and footers of each of 4 pages) at your end?
-Suhas

Hi Suhas,

Thanks for your inquiry. Yes, you can output your Word document in HtmlFixed format while preserving the headers/footers on each page. Please try opening the “out_13.10.0.html” (which is attached to this post*) with Google Chrome web browser or with any browser that supports SVG. Please use Internet Explorer 9 as the earlier versions of IE don’t support SVG. I hope, this helps.

Best regards,