Free Support Forum - aspose.com

Html table contents are not getting displayed

Hi,

I am using Aspose.words (.NET) for processing Word Document.

I am loading Html document which contains table, using aspose.words and converting that document to tiff.

But the whole table contents are not getting displayed only part of the table contents are getting Displayed i.e. table have 10 columns and only 5 columns are getting displayed.

I am using following set of code.

LoadOptions options = new LoadOptions();

options.LoadFormat = LoadFormat.Html;

Document htmlDocument = new Document(@"C:\testing.html", options);

htmlDocument .Save(@"C:\converted.tiff", SaveFormat.Tiff);

How to solve this issue?

Please find the attached html sample file from Zip file.

Thanks.

Hi

Thanks for your request. You can try using the following code before saving to TIFF

// Open document

Document doc = new Document("C:\\Temp\\in.html");

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))

{

FitTableToPageWidth(table);

}

doc.Save("C:\\Temp\\out.tiff");

public static void FitTableToPageWidth(Table table)

{

//Get the page settings from the section where the table occurs, as each section can have different page settings.

Section section = (Section)table.GetAncestor(NodeType.Section);

//First run simply gets the table size (the widest row). This is used to calculate the ratio below instead of just each row length

//as the last cell in one row could be shorter than the last cell in the other row. This will preserve these different sizes when fitting.

double tableWidth = 0;

foreach (Row row in table.Rows)

{

double rowWidth = 0;

foreach (Cell cell in row.Cells)

{

rowWidth += cell.CellFormat.Width;

cell.CellFormat.FitText = true;

}

//If this row is larger than previous set this width as the longest row.

if (rowWidth > tableWidth)

tableWidth = rowWidth;

}

//Calculate the width of the page

double pageWidth = section.PageSetup.PageWidth -

(section.PageSetup.LeftMargin + section.PageSetup.RightMargin);

//In the second run set each cell in the row proportionally to the width of the page

foreach (Row row in table.Rows)

{

foreach (Cell cell in row.Cells)

{

//Calculate the ratio of each cell to the row width and then translate this ratio to the page width.

double cellRatio = cell.CellFormat.Width / tableWidth;

cell.CellFormat.Width = (cellRatio * pageWidth);

}

}

}

Best regards,