Convert Word DOC to HTML & Move Text to New Line after Table with Text Wrapping Set to Around using C# .NET

Dear all,

In the attached ZIP file, there are two Word Document files:

  • document_habillage_tableau-lorem.doc
  • document_habillage_tableau-lorem-workaround.doc

They are respectively saved as HTML content in aspose_html and aspose_workaround_html. A third word_html directory contains a conversion made by Microsoft Word.

The two first documents are converted in HTML format with this trivial piece of code:

Dim doc As Words.Document = New Words.Document(srcPath) 
doc.UpdateFields()
doc.Save(destPath)

In document_habillage_tableau-lorem.doc, the second table has its “Text wrapping” property set to “Around” (see screenshot in the attached ZIP). Since the table width covers the whole page, the text after naturally goes in a new line. However, this is not rendered the same way in the HTML conversion. The text begins next to the table instead after a newline (also the heading number “1.1” is displayed inside the table). Same thing for the conversion made by Microsoft Word.

As a workaround, our client had to set “Text wrapping” to “None” to get a correct rendering (document_habillage_tableau-lorem-workaround.doc)

Since Aspose.Words in this case save this content in HTML the same way Word does, is it still viewed as an issue?

Best regards,
Monir
PS: version 19.8.0 of Aspose.Words is used.

tables_as_html.zip (76.2 KB)

@monir.aittahar,

But, MS Word 2019 also produces a similar output when saving this “document_habillage_tableau-lorem.doc” Word document to HTML format and Aspose.Words 21.4 tries to mimic the behavior of MS Word.

So, this seems to be an expected behavior of Aspose.Words and a limitation of HTML based formats. Alternatively, may be you should convert this document to ‘HTML Fixed format’ i.e. converting the Word document to the HTML format using absolutely positioned elements (HtmlFixed) should produce the expected output for you.

Document doc = new Document("C:\\Temp\\tables_as_html\\document_habillage_tableau-lorem.doc");
HtmlFixedSaveOptions options = new HtmlFixedSaveOptions()
{
    ExportEmbeddedImages = true,
    ExportEmbeddedCss = true,
    PrettyFormat = true
};
doc.Save("C:\\temp\\tables_as_html\\21.4.html", options);

@awais.hafeez,

Thank you for your confirmation. We think to write custom code to set the text wrapping of all (all or matching-criteria) tables to None.

Best regards,
Monir

@monir.aittahar,

In case you have further inquiries or may need any help in future, please let us know.