I have a table with a background color. I noticed there is a way to specify the default cell padding (using table.DefaultCellPadding()), but that leaves a blank space in the background color between tabs. Is there a way to specify a default cell margin?
I tried using the following code to specify margin for a single cell, but it yields a “null reference” error :
Sure, here’s a sample code creating a pdf that reproduces the “problem”. You’ll notice that the first row has a background color but the cell are not fully colored. The cell padding is white. I’d like to have the cell padding the same color as the background…
Aspose.Pdf.Pdf pdfDocument = new Aspose.Pdf.Pdf(); Aspose.Pdf.Section pdfSection; pdfSection = pdfDocument.Sections.Add();
pdfTable = new Aspose.Pdf.Table(); pdfSection.Paragraphs.Add(pdfTable); pdfTable.DefaultCellBorder = new Aspose.Pdf.BorderInfo((int)Aspose.Pdf.BorderSide.All);
You set the background color for text in the cell. This will leave the cell padding not colored. Please set background color for the cell using Cell.BackgroundColor. You can also refer to SettingRowAndColumnFormat.
Thanks, I’ll do that. But, in the exemple you refer to, the background color is set like this :
//set background color for the first row TextInfo tinfo1 = tinfo.Clone() as TextInfo; tinfo1.BackgroundColor = new Color("#0000ff"); tab1.Rows[0].DefaultCellTextInfo = tinfo1;
This is precisely what I’m doing… Your exemple does not include padding however, so the result is the same.
Also, shouldn’t there a way to specify the background color per row instead per cell ? This would save much repetitive coding I would think. Especially when doing alternate row colors on a table with many columns…