Question

I'm using iTextPdf for pdf generation and I'm creating nested table using the below code.

PdfPTable table = new PdfPTable(3);
PdfPTable nestedTable = new PdfPTable(2);
table.addCell(nestedTable);

Now, I want the border width of table to be 0, i.e invisible. I've checked the api and several posts on SO but I couldn't find anything substantial. Is there a way to do so ?

I'm using iText version 5.1.2

Was it helpful?

Solution

In iText PDF api there is no such property to manipulate border directly however as PdfPCell extends Rectangle it has setBorder to manipulate the border. So I've just used the same as a workaround as provided below:

PdfPTable table = new PdfPTable(2);
PdfPTable nestedTable1 = new PdfPTable(1);
PdfPTable nestedTable2 = new PdfPTable(1);

PdfPCell cell = new PdfPCell(new Phrase("StackOverflow"));
newCell.setBorder(Rectangle.NO_BORDER);

nestedTable1.addCell(cell);
nestedTable2.addCell(new Phrase("StackOverflow"));

cellOne = new PdfPCell(nestedTable1);
cellTwo = new PdfPCell(nestedTable2);

cellOne.setBorder(Rectangle.NO_BORDER);

table.addCell(cellOne);
table.addCell(cellTwo);

Output:

                            _______________________
                           |                       | 
      StackOverflow        |     StackOverflow     |
                           |_______________________|
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top