How to get Table Height while Creating Aspose.Word doccument

Hi ,

I want to export HTML to MSWORD using Aspose.Words I have Downloaded free version DLL for R&D.

In that HTML stream Lots of TABLE’S are their and those tables contains Images. if any table not fitted on remaining page it gets split on two different pages . half of rows on one page and half of rows on second page . Image does not show completely.

Is it possible that if entire table does fit on one page then it should shift to next page ?

OR

is their any way so we can find each TABLE’S height, so that as we know Height of page i.e. 11.69’’. one table is fit on page then check the remaining height of page if in that 2nd table can not fix then we can add manually page break.

Please check “Table.Png”

Regards ,
Jeevan Joshi.

Hi Jeevan,

Thanks for your inquiry. You can use RowFormat.Height in order to get/set the height of the table row in points as shown in following code snippet. In your case, please use the RowFormat.Height property when HeightRule is Exactly/AtLeast. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.html");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    double height = 0.0;
    foreach (Row row in table.Rows)
        height += row.RowFormat.Height;
    if (ConvertUtil.PointToInch(height) < 11.69)
    {
        Node parentNode = table.GetAncestor(NodeType.Table);
        if (parentNode == null)
        {
            // Create new paragraph and insert it after table
            Paragraph par = new Paragraph(doc);
            table.ParentNode.InsertAfter(par, table);
            // move documentBuilder cursor to the paragraph
            builder.MoveTo(par);
            // Insert page break
            builder.InsertBreak(BreakType.PageBreak);
        }
    }
}
// Save the output
doc.Save(MyDir + "out.docx");

Hi Tahir ,

Thanks for your reply.

I have done coding as you shown . But problem is that if you haven’t set any height to ROW
in HTML tag then row.RowFormat.Height gives 0.0 and if in case you set any height to and that contains 4 5 rows then also it gives same height e.g. 15.0 it should give more . because it contains 4 5 lines so height of ROW increased .

so finding table height using row.RowFormat.Height this logic not solves my problem .

I want table should not split in 2 pages . if any alternative is their then to do this please give me that to solve this.

See attached “table.png” images for that.

Regards ,
Jeevan Joshi.

Hi Jeevan,

Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behavior as MS Word do. Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting/importing here:
https://docs.aspose.com/words/net/load-in-the-html-html-xhtml-mhtml-format/
https://docs.aspose.com/words/net/save-in-html-xhtml-mhtml-formats/

Regarding the row height issue, please read following documentation link for your kind reference.
https://docs.aspose.com/words/net/applying-formatting/

Could you please attach your input html file here for testing? Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Hi Tahir ,

Thanks for your reply.

I have nested tables in my HTML that I export to word , if one page have 3 tables 4th table can not fit on same page then that table should be shifted on next page , it should not split i.e. 2 3 rows on one page and 2 3 rows on next page.

I have attached “For Export.html” which contains HTML stream which I pass in " builder.InsertHTml() "

“Actual.doc” which I get NOW after Exporting .

“Expected.doc” like which I want export word file should be.

Regards ,
Jeevan Joshi

Hi Jeevan,

Thanks for sharing the document. Please note that Aspose.Words tries to mimic the same behaviour as MS Word do. There is no “Page” concept in Microsoft Word documents. Pages are created by Microsoft Word on the fly.

In your html document, the table’s row has height rule as Auto and some of rows has At Least. In this case, the exact height of table can not be calculated. Please read the detail of Height Rule from here:
https://docs.aspose.com/words/net/applying-formatting/

Please check using the DocumentLayoutHelper sample from the offline samples pack. This sample demonstrates how to easily work with the layout elements of a document and access the pages, lines, spans etc. Hope this helps you.