Recently we came across a problem with table, autofit and paragraphs in a cell
So if we add into a table cell a paragraph in which we inserted 3 different texts of different length, then the table cell column width will be the width of the first text. It should be the width of the largest text.
Attached you can find the reproducer and a sample document generated by this.
public static void ParagraphIssue()
{
// ExStart:MarginsOrPadding
// The path to the documents directory.
var dataDir = “”;
// Instntiate the Document object by calling its empty constructor
var doc = new Document();
var page = doc.Pages.Add();
// Instantiate a table object
var table = new Table { ColumnAdjustment = ColumnAdjustment.AutoFitToContent };
var row1 = table.Rows.Add();
var cell = row1.Cells.Add();
var text1 = new TextFragment(“hello”);
var text2 = new TextFragment(“goodbye”);
var text3 = new TextFragment(“hamana”);
// Row1.Cells.Add(“col3 with large text string to be placed inside cell”);
cell.Paragraphs.Add(text1);
cell.Paragraphs.Add(text2);
cell.Paragraphs.Add(text3);
row1.Cells.Add(“Really really really really long line”);
row1.Cells.Add(“Another Really really long line”);
page.Paragraphs.Add(table);
//Create a Graph object
GraphInfo borderGraph = new GraphInfo { LineWidth = 1 };
//Set table border using customized BorderInfo object
table.DefaultCellBorder = new BorderInfo(BorderSide.All, borderGraph);
dataDir = dataDir + “ParagraphIssue_.pdf”;
// Save the Pdf
doc.Save(dataDir);
public static void ParagraphIssue()
{
// ExStart:MarginsOrPadding
// The path to the documents directory.
var dataDir = “”;
// Instntiate the Document object by calling its empty constructor
var doc = new Document();
var page = doc.Pages.Add();
// Instantiate a table object
var table = new Table { ColumnAdjustment = ColumnAdjustment.AutoFitToContent };
var row1 = table.Rows.Add();
var cell = row1.Cells.Add();
var text1 = new TextFragment(“hello”);
var text2 = new TextFragment(“goodbye”);
var text3 = new TextFragment(“hamana”);
cell.Paragraphs.Add(text1);
cell.Paragraphs.Add(text2);
cell.Paragraphs.Add(text3);
row1.Cells.Add(“Really really really really long line”);
row1.Cells.Add(“Another Really really long line”);
page.Paragraphs.Add(table);
//Create a Graph object
GraphInfo borderGraph = new GraphInfo { LineWidth = 1 };
//Set table border using customized BorderInfo object
table.DefaultCellBorder = new BorderInfo(BorderSide.All, borderGraph);
dataDir = dataDir + “ParagraphIssue_.pdf”;
// Save the Pdf
doc.Save(dataDir);
// ExEnd:MarginsOrPadding
Console.WriteLine("\nCell and table border width setup successfully.\nFile saved at " + dataDir);
}
}