Hello Aspose,
I want to set the format of a text in table cell, but this is not working. Only FontStyles.Italic is set and otherwise the DefaultCellTextState is used.
grafik.png (3.4 KB)
See following code to reproduce.
public static void Main()
{
Document doc = new Document();
Page page = doc.Pages.Add();
var file = TableContentFormat(page);
if (File.Exists(file)) { File.Delete(file); }
doc.Save(file);
Process.Start(file);
}
private static string TableContentFormat(Page page)
{
var table = new Table()
{
ColumnWidths = null,
Alignment = HorizontalAlignment.Left,
ColumnAdjustment = ColumnAdjustment.AutoFitToWindow,
DefaultColumnWidth = "100",
RepeatingColumnsCount = 0,
RepeatingRowsCount = 1,
Broken = TableBroken.None,
IsBroken = true,
DefaultCellBorder = null,
DefaultCellPadding = null,
DefaultCellTextState = new TextState("Arial", false, false)
{
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 9F,
LineSpacing = 0,
BackgroundColor = Color.AliceBlue,
ForegroundColor = Color.Green
},
Margin = new MarginInfo() { Left = 0, Top = 20, Right = 0, Bottom = 20 },
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Left,
IsFirstParagraphInColumn = false,
IsInLineParagraph = false,
IsInNewPage = false,
IsKeptWithNext = false,
};
var r1 = new Row()
{
BackgroundColor = Color.Black,
FixedRowHeight = 0,
MinRowHeight = 0,
IsInNewPage = false,
IsRowBroken = false,
VerticalAlignment = VerticalAlignment.None,
DefaultCellPadding = null,
DefaultCellBorder = null,
Border = null
};
var r2 = new Row()
{
BackgroundColor = Color.Black,
FixedRowHeight = 0,
MinRowHeight = 0,
IsInNewPage = false,
IsRowBroken = false,
VerticalAlignment = VerticalAlignment.None,
DefaultCellPadding = null,
DefaultCellBorder = null,
Border = null
};
var r3 = new Row()
{
BackgroundColor = Color.Black,
FixedRowHeight = 0,
MinRowHeight = 0,
IsInNewPage = false,
IsRowBroken = false,
VerticalAlignment = VerticalAlignment.None,
DefaultCellPadding = null,
DefaultCellBorder = null,
Border = null
};
table.Rows.Add(r1);
table.Rows.Add(r2);
table.Rows.Add(r3);
var c11 = new Cell()
{
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 2,
RowSpan = 1,
Margin = new MarginInfo() { Left = 7, Top = 10, Right = 7, Bottom = 10 },
Border = new BorderInfo(BorderSide.All, 1.0F, Color.White),
DefaultCellTextState = new TextState("Arial", true, false)
{
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 9F,
LineSpacing = 1,
BackgroundColor = Color.AliceBlue,
ForegroundColor = Color.White
},
BackgroundColor = Color.AliceBlue,
Paragraphs = { new TextFragment("Hello") }
};
r1.Cells.Add(c11);
var c21 = new Cell()
{
//Width = 0,
Alignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center,
IsNoBorder = false,
IsOverrideByFragment = false,
IsWordWrapped = true,
ColSpan = 1,
RowSpan = 1,
Margin = new MarginInfo() { Left = 7, Top = 10, Right = 7, Bottom = 10 },
Border = new BorderInfo(BorderSide.All, 0.5F, Color.White),
DefaultCellTextState = new TextState("Helvetica", false, false)
{
HorizontalAlignment = HorizontalAlignment.Left,
FontSize = 9F,
LineSpacing = 1,
BackgroundColor = Color.Yellow,
ForegroundColor = Color.DarkMagenta
},
BackgroundColor = Color.LightBlue,
};
var c22 = c21.Clone() as Cell;
var c31 = c21.Clone() as Cell;
var c32 = c21.Clone() as Cell;
var t = new TextFragment("1-1")
{
TextState =
{
FontSize = 25.0F,
ForegroundColor = Color.DeepPink,
BackgroundColor = Color.Red,
FontStyle = FontStyles.Italic
}
};
c21.Paragraphs.Add(t);
c22.Paragraphs.Add(new TextFragment("1-2"));
c31.Paragraphs.Add(new TextFragment("2-1"));
c32.Paragraphs.Add(new TextFragment("2-2"));
r2.Cells.Add(c21);
r2.Cells.Add(c22);
r3.Cells.Add(c31);
r3.Cells.Add(c32);
page.Paragraphs.Add(table);
return Path.Combine(myDataDir, "TableContentFormat.pdf");
}
What I need is kind of invisible marker in a table to search for with the table absorber for. This marker shall not incluence the position of the following text in this cell. So fontsize 0 would be ideal.
Is there a workaround for?
Regards
Gerd