Having some problems converting to a pdf and keeping styling inside tables. I’m trying to create boxes that have vertically and horizontally centered text, but here is what I’m getting.
Relevant code:
Table builderTable = builder.StartTable();
builder.RowFormat.HeightRule = HeightRule.AtLeast;
builder.RowFormat.Height = tempVariable.AdvancedTable.RowHeight;
Cell cell = builder.InsertCell();
builder.InsertField($"MERGEFIELD TableStart:{tempVariable.VariableName}");
this.SetCellStyling(tempVariable.AdvancedTable.Rows.First().Cells.First(), cell, builder);
for (var columnIndex = 0; columnIndex < columnNames.Length; columnIndex++)
{
builder.InsertField($"MERGEFIELD {columnNames[columnIndex]}");
string lastItem = columnNames[columnNames.Length - 1];
if (columnNames[columnIndex] != lastItem)
{
cell = builder.InsertCell();
this.SetCellStyling(tempVariable.AdvancedTable.Rows.First().Cells.Skip(columnIndex + 1).First(), cell, builder);
}
}
builderTable.AllowAutoFit = false;
builderTable.PreferredWidth = PreferredWidth.FromPercent(tempVariable.AdvancedTable.BuilderTablePreferredWidth);
builderTable.Alignment = TableAlignment.Right;
builderTable.TextWrapping = TextWrapping.Around;
builder.InsertField($"MERGEFIELD TableEnd:{tempVariable.VariableName}");
builder.EndTable();
ds.Tables.Add(table);
private void SetCellStyling(AdvancedCell cell, Cell asposeCell, DocumentBuilder builder)
{
if (cell.HorizontalTextAlignment != HorizontalTextAlignmentType.None)
{
builder.ParagraphFormat.Alignment = this.GetHorizontalStyle(cell.HorizontalTextAlignment);
}
if (cell.VerticalTextAlignment != VerticalTextAlignmentType.None)
{
asposeCell.CellFormat.VerticalAlignment = this.GetVerticalStyle(cell.VerticalTextAlignment);
}
this.SetBorder(cell, asposeCell);
}
private ParagraphAlignment GetHorizontalStyle(HorizontalTextAlignmentType alignment)
{
switch (alignment)
{
case HorizontalTextAlignmentType.Left: return ParagraphAlignment.Left;
case HorizontalTextAlignmentType.Right: return ParagraphAlignment.Right;
case HorizontalTextAlignmentType.Center: return ParagraphAlignment.Center;
}
return ParagraphAlignment.Left;
}
I’ve verified that the variables passed in have the correct styling setting passed in and set in Aspose.
Any ideas on why it’s not vertically or horizontally centered inside the table?