Hi,
Thanks for using our products.
As per my current understanding, you have first created DataTable object and then have copied all its data to DataGrid. Finally the contents from DataGrid are imported to Table object being placed inside PDF document. Instead of using DataGrid, you may also directly import the contents from DataTable to table object. Please take a look over following code snippet and the resultant PDF that I have generated using Aspose.Pdf for .NET 6.1.0. I just have observed that when table is spanning more than one page, some contents are being placed outside of bottom table margin. For the sake of correction, I have logged it as PDFNEWNET-29927 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.
[C#]
DataTable dt = new DataTable();
dt.Columns.Add();
dt.Columns.Add();
dt.Columns.Add();
dt.Columns.Add();
dt.Columns.Add();
dt.Columns.Add();
dt.Columns.Add();
DataRow dr = dt.NewRow();
dr[0] = "Date";
dr[1] = "ref";
dr[2] = "rinterne";
dr[3] = "lib";
dr[4] = "evt";
dr[5] = "debit";
dr[6] = "credit";
dt.Rows.Add(dr);
for (int i = 0; i < 100; i++)
{
dr = dt.NewRow();
dr[0] = "12/01/2011";
dr[1] = "CNT";
dr[2] = "99999";
dr[3] = "lalala";
dr[4] = "210005452";
dr[5] = "0.13";
dr[6] = "0.13";
dt.Rows.Add(dr);
}
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Table tab = new Aspose.Pdf.Generator.Table();
// set the columns width information
tab.ColumnWidths = ("80 80 80 80 80 80 80");
// set the border style for table
tab.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.5f);
// set the default cell padding
tab.DefaultCellPadding.Left = tab.DefaultCellPadding.Right = tab.DefaultCellPadding.Top = tab.DefaultCellPadding.Bottom= 5;
// specify the font name for table contents
tab.DefaultCellTextInfo.FontName = "Arial";
// set the Horizontal alignment information for table contents as Center aligned
tab.DefaultCellTextInfo.Alignment = Aspose.Pdf.Generator.AlignmentType.Center;
//tab.ImportDataGrid(dg, 0, 0, dg.Items.Count + 1, 7);
tab.ImportDataTable(dt, false, 0, 0, dt.Rows.Count, dt.Columns.Count);
// set the background color information for first row of table as Silver
tab.Rows[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Silver");
// set contents of first row as Bold
tab.Rows[0].DefaultCellTextInfo.IsTrueTypeFontBold = true;
// set the background color information for Second row of table as Silver
tab.Rows[1].BackgroundColor = new Aspose.Pdf.Generator.Color("Silver");
for (int Row_Counter = 0; Row_Counter < tab.Rows.Count; Row_Counter++)
{
// specify the fix row height information for table cells
//tab.Rows[Row_Counter].FixedRowHeight = 20;
// set the background color information for first column of row
tab.Rows[Row_Counter].Cells[0].BackgroundColor = new Aspose.Pdf.Generator.Color("Silver");
}
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
section.Paragraphs.Add(tab);
pdf.IsLandscape = true;
pdf.Save("d:/pdftest/DatGrid_Issue.pdf");