Background color in table cells with padding


#1

I am in the process of evaluating your Aspose.pdf tool and have run into a small snag I hope you can help me with.

I have a table with some default cell padding and borders.

table1.DefaultCellPadding.Top = 4;
table1.DefaultCellPadding.Bottom = 1;
table1.DefaultCellPadding.Left = 2;
table1.DefaultCellPadding.Right = 2;
table1.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.5F);

I need to have BackgroundColor set for some of the cells. When I turn it on for a cell, the background does not completely cover the cell. It looks as though the padding area is still white.

Is there a better way to do this so that the whole cell will have the background color? I need the cell padding because I don’t want the text right next to the cell borders.

Any help is appreciated. Thanks.


#2

Dear gibsoju,

Thank you for considering Aspose.

I have tested it and have not found the error. Here is my code:

string[] data = new String[]{“Employee_ID”,“Employee_Name”,“Gender”,“1”,“John Smith”,“Male”,
“2”,“Mary Miller”,“Female”};

Pdf pdf1 = new Pdf(@“e:\projects\CSharp\customer\Aspose.Pdf.lic”);

Section sec1 = pdf1.Sections.Add();

Table tab1 = new Table();
sec1.Paragraphs.Add(tab1);
tab1.ColumnWidths = “40 100 100 100”;
tab1.DefaultCellPadding.Top = 4;
tab1.DefaultCellPadding.Bottom = 1;
tab1.DefaultCellPadding.Left = 2;
tab1.DefaultCellPadding.Right = 2;
tab1.DefaultCellBorder = new BorderInfo((int)BorderSide.All,0.5F);

tab1.ImportArray(data,0,1,false);

Row row1 = tab1.Rows[0];
foreach(Cell curCell in row1.Cells)
curCell.BackgroundColor = new Color(“Blue”);

pdf1.Save(“e:/temp/test.pdf”);


If you still can’t get it work, please post your complete code or send it to me via email.


#3

I did not see the BackgroundColor property on the Cell. I was trying to change the background color through the DefaultCellTextInfo property. Cell.BackgroupColor works perfectly. Thank you.