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

Free Support Forum - aspose.com

Table row background issue

Hi Support,

We are using aspose word for HTML to docx conversion. To set the page level background we created a table in the background and set the cell color. It works fine when we have the single page or just the two column layout but it fails when we have two rows and the second row has two column. Please check the attachment for details.

Our problem is to stretch the second-row first column background color till the end of the page even there is no text.

What we have tried:
We have added a third row programmatically to fill the remaining document as we want to extend the shape/color on left side till the end of every page independent of whether text exists or not till the end or not. Left-hand side color should be rendered for every page.

We are looking for a way to find out the rendered height which we can use for last table cell as right now we have hardcoded it.

The first section(with black background) in the document which contains name is a row and rest of the data is present in the second row. We tried fixing second-row height equal to doc height but then the second row would render in a separate page.

Below is the code snippet that we use to add the third row in our doc:

Row rowLast = new Row(doc);

                        Cell cellOne = new Cell(doc);
                        cellOne.CellFormat.Borders.ClearFormatting();
                        cellOne.CellFormat.Width = table.Rows[1].Cells[0].CellFormat.Width;
                        cellOne.CellFormat.Shading.BackgroundPatternColor =                              table.Rows[1].Cells[0].CellFormat.Shading.BackgroundPatternColor;

                        Cell cellTwo = new Cell(doc);
                        cellTwo.CellFormat.Width = table.Rows[1].Cells[1].CellFormat.Width;
                        cellTwo.CellFormat.Borders.ClearFormatting();
                        cellTwo.CellFormat.Shading.BackgroundPatternColor = table.Rows[1].Cells[1].CellFormat.Shading.BackgroundPatternColor;

                        rowLast.RowFormat.Height = 261;
                        rowLast.RowFormat.HeightRule = HeightRule.AtLeast;
                        rowLast.AppendChild(cellOne);
                        rowLast.AppendChild(cellTwo);
                        rowLast.RowFormat.Borders.ClearFormatting();
                        table.AppendChild(rowLast);

Please check the attached docx.
Sample Docx.zip (75.6 KB)
Attachemnt contains three docx files one it the our desired output.
Second that we are getting right now.
Third, we tried to set the second at least heigh to page height but this creates the gap between first and second row.

Thanks,
Pawan

@pawanbold,

Thanks for your inquiry. In your case, we suggest you following solution.

  1. Get the position of last paragraph of table using Aspose.Words.Layout API. E.g. value1
  2. Get the page’s height using PageSetup.PageHeight property. E.g. value2
  3. Add the new row to table and set its height by getting the difference of value2 and value1.

Following code example show how to use layout API. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
Table table = doc.FirstSection.Body.Tables[0];

LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);

enumerator.Current = collector.GetEntity(table.LastRow.LastCell.LastParagraph);
double position = enumerator.Rectangle.Top;
Console.WriteLine(position);
Console.WriteLine(table.FirstRow.FirstCell.FirstParagraph.ParentSection.PageSetup.PageHeight);