Dear customers,
Thanks for your consideration.
In this fix, formatting table in API is simplified. Please view thread How to format table? about customer requirement.
-
A new property DefaultCellTextState is added to Row class. This property is used to set text format info for all cells in this row. If you want to set text format for all cells that have already been added to the row, please do not set it directly but follow the example below.
-
A new method SetColumnTextInfo is added to Table class. This method is used to set text format info for all cells in the column.
-
A new property IsBuffered is added to Pdf class. This property indicates whether memory buffer is used when generating PDF document. The default value is true. If this property is set to false, Aspose.Pdf will write document directly to PDF file and the GetBuffer method can’t be used.
-
Two new methods GetMinColumnWidth and SetColumnWidth are added to Table class. These tow methods are used to adjust column width after the table has been created.
Here is an example about how to format table. In the example, we import array into a table, set the background color of the first row and right align text in the last column.
[C#]
Pdf pdf1 = new Pdf();
Section sec1 = pdf1.Sections.Add();
Table tab1 = new Table();
sec1.Paragraphs.Add(tab1);
tab1.ColumnWidths = “60 100 100”;
TextInfo tinfo = new TextInfo();
tinfo.FontName = “Courier”;
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.1F);
tab1.DefaultCellTextInfo = tinfo;
double[] darr = new Double[]{1.5,3.1415926,100000,20,4000,30.4512,45.67,890,23.45};
tab1.ImportArray(darr,0,0,false);
//set background color for the first row
TextInfo tinfo1 = tinfo.Clone() as TextInfo;
tinfo1.BackgroundColor = new Color("#0000ff");
tab1.Rows[0].DefaultCellTextInfo = tinfo1;
//right align text in the last column
TextInfo tinfo2 = tinfo.Clone() as TextInfo;
tinfo2.Alignment = AlignmentType.Right;
tab1.SetColumnTextInfo(2,tinfo2);
//we have to reset the upper-right cell
tinfo1.Alignment = AlignmentType.Right;
tab1.Rows[0].Cells[2].DefaultCellTextInfo = tinfo1;
[VisualBasic]
Dim pdf1 As Pdf = New Pdf()
Dim sec1 As Section = pdf1.Sections.Add()
Dim tab1 As Table = New Table()
sec1.Paragraphs.Add(tab1)
tab1.ColumnWidths = “60 100 100”
Dim tinfo As TextInfo = New TextInfo()
tinfo.FontName = “Courier”
tab1.DefaultCellBorder = New BorderInfo(CType(BorderSide.All, Integer), 0.1)
tab1.DefaultCellTextInfo = tinfo
Dim darr() As Double = New Double() {1.5, 3.1415926, 100000, 20, 4000, 30.4512, 45.67, 890, 23.45}
tab1.ImportArray(darr, 0, 0, False)
'set background color for the first row
Dim tinfo1 As TextInfo = tinfo.Clone()
tinfo1.BackgroundColor = New Aspose.Pdf.Color("#0000ff")
tab1.Rows(0).DefaultCellTextInfo = tinfo1
'right align text in the last column
Dim tinfo2 As TextInfo = tinfo.Clone()
tinfo2.Alignment = AlignmentType.Right
tab1.SetColumnTextInfo(2, tinfo2)
'we have to reset the upper-right cell
tinfo1.Alignment = AlignmentType.Right
tab1.Rows(0).Cells(2).DefaultCellTextInfo = tinfo1
Please download hot fix here.