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

Free Support Forum - aspose.com

Converting RTF to HTML

I’m trying to convert RTF to HTML. The conversion works as expected, but I cannot find an option to not write the headers, and export only the body content of the HTML file. Am I missing an option?

Hi Stig Runar,

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

When this property is PER_SECTION, Aspose.Words exports only primary headers and footers at the beginning and the end of each section. When it is FIRST_SECTION_HEADER_LAST_SECTION_FOOTER only first primary header and the last primary footer (including linked to previous) are exported. Please read about ExportHeadersFootersMode from here:
https://reference.aspose.com/words/java/com.aspose.words/ExportHeadersFootersMode

You can disable export of headers and footers altogether by setting this property to NONE.

Document doc = new Document(MyDir + "HeaderFooter.RemoveFooters.doc");
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
saveOptions.setExportHeadersFootersMode(ExportHeadersFootersMode.NONE); // Disables exporting headers and footers.
doc.save(MyDir + "HeaderFooter.DisableHeadersFooters Out.html", saveOptions);

I might have been unclear in my question. What I meant by exporting only body content, was not how to exclude the input document header and footer. What I meant, was that I need some option to export only the content between the and tags of the HTML document.

Hi Stig,

Thanks for your inquiry. I think, you can achieve this by iterating through all Sections in your RTF and individually exporting each Section’s Body to HTML format. Please see the following line of code for example:

Document.FirstSection.Body.ToString(SaveFormat.Html);

I hope, this helps.

Best regards,