Table Default Cell Margin (not padding)

Hi,

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 :


str = “some text”;
pdfCell = pdfRow.Cells.Add(str);
pdfCell.Margin.Left = 30;
The following yield no error but just doesn’t work :

str = “some text”;
pdfCell = pdfRow.Cells.Add(str);
pdfCell.Margin = new Aspose.Pdf.MarginInfo();
pdfCell.Margin.Left = 30;
Any ideas ? Thanks.
Dominic.

Version used : 2.5.0.0

Dear Dominic,

Thank you for considering Aspose.Pdf.

  1. Please refer to BorderMarginAndPadding. Cell margin is not supported.
  2. I have tested cell padding with background color wothout any error. Can you please provide an example that can reproduce this problem?

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();

// Create table
Aspose.Pdf.Table pdfTable;
Aspose.Pdf.Row pdfRow;
Aspose.Pdf.Cell pdfCell;
Aspose.Pdf.TextInfo pdfTextInfo;
string str;

pdfTable = new Aspose.Pdf.Table();
pdfSection.Paragraphs.Add(pdfTable);
pdfTable.DefaultCellBorder = new Aspose.Pdf.BorderInfo((int)Aspose.Pdf.BorderSide.All);

pdfTable.DefaultCellPadding.Top = 5;
pdfTable.DefaultCellPadding.Right = 5;
pdfTable.DefaultCellPadding.Bottom = 5;
pdfTable.DefaultCellPadding.Left = 5;

// Output header row
pdfRow = pdfTable.Rows.Add();
pdfRow.DefaultCellTextInfo.BackgroundColor = new Aspose.Pdf.Color("#cccccc");

// columns
str = “first”;
pdfTextInfo = pdfRow.DefaultCellTextInfo.Clone() as Aspose.Pdf.TextInfo;
pdfCell = pdfRow.Cells.Add(str, pdfTextInfo);

str = “second”;
pdfTextInfo = pdfRow.DefaultCellTextInfo.Clone() as Aspose.Pdf.TextInfo;
pdfCell = pdfRow.Cells.Add(str, pdfTextInfo);

// second row
pdfRow = pdfTable.Rows.Add();

str = “1”;
pdfRow.Cells.Add(str);

str = “2”;
pdfRow.Cells.Add(str);

return pdfDocument;


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…

Thanks.
Dominic.

Dear Dominic,

I will add a new property BackgroundColor to Row class in newer version.

Hi Tommy,

Do you have an estimation of when the new version will be posted with this change?

Thanks,

Ryan

Dear Ryan,

Thank you for considering Aspose.

Sorry there are so many urgent task and I have not finished this function. I hope it will be available in next week.