We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ImportDatagrid and color


I defined a datagrid and imported it to aspose by the ImportDatagrid method, but colours are not displayed in the resultant PDF.

Is it normal ?

code is in attachment with the resultant PDF and the resultant ASPX page.

I work with .net 1.1, VS2003 and Aspose 6.1.



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.


DataTable dt = new DataTable();

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";

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";

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();
pdf.IsLandscape = true;


I tryed to import a datagrid because there is a pb with colors when i import a datatable (see my other post "Pb with IsFixedHeight, BackgroundColor and number of lines" in that forum).

Conclusion : I 'll keep the aspose Pdf 3.4 for .Net 1.1 because aspose.Pdf 6.1 is not compatible.


The colors and formatting information is defined against DataGrid and when using ImportDataGrid(…) method, only data is copied and formatting information is not copied. As the table is an object in Aspose.Pdf for .NET Document Object Model, so you need to explicitly define the formatting against Table object.

If you are facing an issue while using ImportDataTable(…), you may continue using the ImportDataGrid(…) method and define formatting information such as background color, Justification, Bold etc, as I have shared in my earlier post. In the event of any further query, please feel free to contact. We apologize for your inconvenience.

The issues you have found earlier (filed as 29927 ) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.