@awais.hafeez- I am getting following error for some document when i am using above code to reduce the table font and set in page width:
5544 18:57:53 ERROR GenerateFiles
Exception: System.Threading.ThreadAbortException
Message: Thread was being aborted.
Source: mscorlib
at System.String.IndexOf(Char value, Int32 startIndex, Int32 count)
at .(Char )
at .(Int32 )
at .()
at ..ctor(Inline , , String , )
at .(Inline , String , Boolean )
at . ()
at .()
at .()
at Aspose.Words.Document.UpdatePageLayout()
at Aspose.Words.Layout.LayoutEnumerator.Reset()
at Informa.Library.Article.Helpers.ExportAssetFamilyHelper.GetTableWidth(Table table) in D:\JenkinsBuilds\workspace\Sitecore-UAT-Build\OmdiaUAT-Build\src\Informa.Library\Article\Helpers\ExportAssetFamilyHelper.cs:line 503
at Informa.Library.Article.Helpers.ExportAssetFamilyHelper.StyleTables(Document doc) in D:\JenkinsBuilds\workspace\Sitecore-UAT-Build\OmdiaUAT-Build\src\Informa.Library\Article\Helpers\ExportAssetFamilyHelper.cs:line 484
at Informa.Library.Article.Helpers.ExportAssetFamilyHelper.GenerateFiles(String articleName, String htmlContent, ExportHeader header, Configurations configs) in D:\JenkinsBuilds\workspace\Sitecore-UAT-Build\OmdiaUAT-Build\src\Informa.Library\Article\Helpers\ExportAssetFamilyHelper.cs:line 409
private static void StyleTables(Document doc)
{
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
foreach (Table table in tables)
{
foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))
{
cell.EnsureMinimum();
foreach (Paragraph para in cell.Paragraphs)
if (!(cell.ParentRow.IsLastRow && para.IsEndOfCell))
para.ParagraphFormat.KeepWithNext = true;
}
Section tableSection = (Section)table.GetAncestor(NodeType.Section);
double pageWidth = tableSection.PageSetup.PageWidth - tableSection.PageSetup.RightMargin;
while (Math.Round(GetTableWidth(table)) > Math.Round(pageWidth))
{
foreach (Paragraph paragraph in table.GetChildNodes(NodeType.Paragraph, true))
{
paragraph.ParagraphBreakFont.Size = paragraph.ParagraphBreakFont.Size - 1;
foreach (Run run in paragraph.GetChildNodes(NodeType.Run, true))
run.Font.Size = run.Font.Size - 1;
}
doc.UpdateTableLayout();
doc.UpdatePageLayout();
}
};
}
public static double GetTableWidth(Table table)
{
LayoutCollector collector = new LayoutCollector((Document)table.Document);
**LayoutEnumerator enumerator = new LayoutEnumerator((Document)table.Document);**
double maxWidth = 0;
foreach (Row row in table.Rows)
{
if (row != null && row.LastCell != null && row.LastCell.FirstParagraph != null)
{
var entity = collector.GetEntity(row.LastCell.FirstParagraph);
if (entity != null)
{
enumerator.Current = entity;
while (enumerator.MoveParent())
if (enumerator.Type == LayoutEntityType.Row)
break;
// Get the width of Row
double rowWidth = enumerator.Rectangle.Right;
if ((rowWidth > maxWidth))
maxWidth = rowWidth;
}
}
}
return maxWidth;
}
Code line in ** where it is breaking. Could you please let me know the issue here? It blocking thread and site going in non responding state due to this.
Thanks