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

Free Support Forum - aspose.com

Aspose.Pdf : Setting Cellpadding on a row instead of each cell

Hi,

I am using Aspose.Pdf for ASP.NET C# trial version 4.2.1.0

I am trying to create a table that has a DefaultCellPadding set but then some rows in that table need a different cellpadding than the default.

Is there a way to set the cellpadding on the row object instead of on each cell in that row?

The code below works (it is a very simplified version of what I’m working with) but I would rather use something like indentRow.CellPadding.Left = 20 instead of setting it on each cell.

Aspose.Pdf.Section sec = pdf.Sections.Add();

Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
sec.Paragraphs.Add(tab);
tab.DefaultCellPadding.Left = 10;
tab.DefaultCellPadding.Right = 10;
tab.DefaultCellPadding.Top = 10;
tab.DefaultCellPadding.Bottom = 10;
tab.ColumnAdjustment = ColumnAdjustmentType.AutoFitToWindow;
tab.Alignment = AlignmentType.Center;
tab.DefaultCellBorder = new BorderInfo((int)BorderSide.All);


Aspose.Pdf.Row row1 = tab.Rows.Add();
Aspose.Pdf.Cell cell1 = row1.Cells.Add(“Cell 1”);
Aspose.Pdf.Cell cell2 = row1.Cells.Add(“Cell 2”);

Aspose.Pdf.Row indentRow = tab.Rows.Add();
Aspose.Pdf.Cell cell3 = indentRow.Cells.Add(“Cell 3”);
cell3.Padding.Left = 20;
Aspose.Pdf.Cell cell4 = indentRow.Cells.Add(“Cell 4”);
cell4.Padding.Left = 20;

Thanks!
-Jane

Hello jane,

The required feature is currently not available but, for the sake of correction, I have logged it as new feature in our issue tracking system as PDFNET-17407. We will investigate this issue in details and will keep you updated on the status of a correction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

We apologize for your inconvenience.

Hello jane,

Thanks for your patience.

I am pleased to inform you that with the release of Aspose.Pdf for .NET 4.6.0, a new property named DefaultRowCellPadding has been introduced in Row class which offers the capability to specify the default cell padding of a row. Please take a look over the following code snippet and the resultant PDF that I have generated. You may download Aspose.Pdf for .NET 4.6.0 from here.

[C#]

Pdf pdf = new Pdf();
Aspose.Pdf.Section sec = pdf.Sections.Add();

Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
sec.Paragraphs.Add(tab);
tab.DefaultCellPadding.Left = 10;
tab.DefaultCellPadding.Right = 10;
tab.DefaultCellPadding.Top = 10;
tab.DefaultCellPadding.Bottom = 10;

tab.ColumnAdjustment = ColumnAdjustmentType.AutoFitToWindow;
tab.Alignment = Aspose.Pdf.AlignmentType.Center;
tab.DefaultCellBorder = new BorderInfo((int)BorderSide.All);

Aspose.Pdf.Row row1 = tab.Rows.Add();
Aspose.Pdf.Cell cell1 = row1.Cells.Add("Cell 1");
Aspose.Pdf.Cell cell2 = row1.Cells.Add("Cell 2");

Aspose.Pdf.Row indentRow = tab.Rows.Add();
indentRow.DefaultRowCellPadding = new MarginInfo();
indentRow.DefaultRowCellPadding.Left = 50;
indentRow.DefaultRowCellPadding.Right = 50;
indentRow.DefaultRowCellPadding.Top = 50;
indentRow.DefaultRowCellPadding.Bottom = 50;

Aspose.Pdf.Cell cell3 = indentRow.Cells.Add("Cell 3");
Aspose.Pdf.Cell cell4 = indentRow.Cells.Add("Cell 4");
pdf.Save(@"D:/pdftest/RowPadding_in_PDF.pdf");