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

Free Support Forum - aspose.com

Not able to add border for first row only in the table using aspose pdf

Hi,

I used the following code to add border for first row only, there is no error while debugging but the border is not showing in the pdf.

Aspose.Pdf.Generator.Table keycomp = new Aspose.Pdf.Generator.Table();
keycomp.Rows[0].DefaultCellBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.Bottom, 0.2F);

and I am using framework 3.5

Hi Ashok,


Thanks for your inquiry. We have noticed the border issue in Aspose.Pdf.Generator package. However please note this package is about to obsolete, we are not fixing the issues in this package anymore. We have another package Aspose.Pdf.Document (DOM approach) can be used both for creating PDF files from scratch and manipulate existing PDF files. It is more improved and efficient than old generator. You may use following code snippet to add a table and set border of first row only. Please also check documentation link for working with Tables in DOM approach. Hopefully it will help you to accomplish the task.

// Create a PDF
document
<o:p></o:p>

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

Page page = doc.Pages.Add();

// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

// create a loop to add 10 rows

for (int row_count = 1; row_count < 10; row_count++)

{

// add row to table

Aspose.Pdf.Row row = table.Rows.Add();

// add table cells

row.Cells.Add("Column (" + row_count + ", 1)");

row.Cells.Add("Column (" + row_count + ", 2)");

row.Cells.Add("Column (" + row_count + ", 3)");

}

// Add table object to first page of input document

page.Paragraphs.Add(table);

// set the border for table cells

table.Rows[0].DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.Bottom, .2f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// Save updated document containing table object

doc.Save(myDir+"document_with_table.pdf");

Please feel free to contact us for any further assistance.


Best Regards,