Free Support Forum - aspose.com

Not able to set border for a single side of a cell

I am trying to set border of a cell (Ex: left) to be displayed and other three sides to be blank. I have tried several combinations and have not succeeded. It is either all sides are none. Please let me know how to achieve this using Aspose.pdf in java.

Hi Lakshminath,

Thanks for using our products.

In case you need to specify a certain border side for table cell, please use that value from BorderSide enumeration. As per your requirement of setting only left border side for table cell, please try using following code line

//Set top border information for second cell of row
row1.getCells().getCell(1).setBorder(new BorderInfo(BorderSide.Left.getValue(), 0.5F));

Please ensure that you have
not specified the default border information for whole table object.
Please take a look over following complete code snippet and the
resultant PDF document that I have generated with Aspose.Pdf for Java
3.0.1.


[Java]


// create PDF instance
Pdf pdf = new Pdf();
aspose.pdf.Section sec1 = pdf.getSections().add();
//Instantiate a table object
aspose.pdf.Table table = new aspose.pdf.Table(sec1);
//Add the table in paragraphs collection of the desired section
sec1.getParagraphs().add(table);
//Set with column widths of the table
table.setColumnWidths(“50 50 50”);
//Create MarginInfo object and set its left, bottom, right and top margins
aspose.pdf.MarginInfo margin = new aspose.pdf.MarginInfo();
margin.setLeft(5f);
margin.setTop(5f);
margin.setRight(5f);
margin.setBottom(5f);
//Set the default cell padding to the MarginInfo object
table.setDefaultCellPadding(margin);
//Create rows in the table and then cells in the rows
aspose.pdf.Row row1 = table.getRows().add();
row1.getCells().add(“col1”);
row1.getCells().add(“col2”);
//Set top border information for second cell of row
row1.getCells().getCell(1).setBorder(new BorderInfo(BorderSide.Left.getValue(), 0.5F));
row1.getCells().add(“col3”);
// save the resultant PDF
pdf.save(“D:\pdftest\TableBorder-test.pdf”);

Sir/Madam,

I have copied the source code provided by you as it is and created a pdf, but it did not produce the desired reults. None of the cells had any borders.

Could it be that we are using different versions of the Aspose?

Regards,

Hi Lakshminath,

Please try using the latest release version of Aspose.Pdf for Java 3.0.1 and in case you still face similar problem, please share some details regarding your working environment i.e. OS, JDK version etc. We are sorry for your inconvenience.