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

Free Support Forum - aspose.com

Table AutoFit

Hi there,

some of the tables in my word document goes out of the page. Is there any way to fit them inside a word window.

Like before Aspose.Words I am fixing this by using MS word Office component:

What is the approach of Aspose.words to fix the same?



<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. We are currently looking into supporting auto fitting a table to page width. Your request for the feature has been noted and we will inform you of any developments.

In the mean time you can still achieve this by using code similar to what’s used in this thread:

Hope this helps.

Best regards,

Hi there,

In addition, please check out the article here which provides full code for fitting a table to page width.


Hi there,

Thanks for your additional information. The above provided solution works fine, but it leads to another issue.

If the table having only two columns and it occupies half of the page width, after applying previous thread technique, the smaller tables are stretched to fit the page width and same is happening if the header/footer have small tables, those too stretched. Is there any other approach to fix the same thing…?


Hi there,

Thanks for your inquiry.

Please try this extra code below:

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />





public static bool TableIsOutsidePageWidth(Table table)


double tableWidth = 0;

foreach (Row row in table.Rows)


double rowWidth = 0;

foreach (Cell cell in row.Cells)

rowWidth += cell.CellFormat.Width;

tableWidth = Math.Max(tableWidth, rowWidth);


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

double sectionPageWidth = section.PageSetup.PageWidth - (section.PageSetup.LeftMargin + section.PageSetup.RightMargin);

if (tableWidth > sectionPageWidth)

return true;


return false;



The issues you have found earlier (filed as WORDSNET-352) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.