2

I want to remove the entire border of a table in iText 7.

Until 7.0.8 it was possible to add strings to cells (source):

Cell cell = new Cell();
cell.add("contents go here");
cell.setBorder(Border.NO_BORDER);
table.addCell(cell);

But as per 7.1.6 strings can't be added to cells anymore, only IBlockElement or Image.

This one would be a workaround:

Cell cell;

cell = new Cell().add(new Paragraph("some text"));
cell.setBorder(Border.NO_BORDER);
table.addCell(cell);

cell = new Cell().add(new Paragraph("more text"));
cell.setBorder(Border.NO_BORDER);
table.addCell(cell);

// repeat x times

But it obviously isn't the preferred way if you have many cells.


So how can I remove the border of a table now?

Simply doing table.setBorder(Border.NO_BORDER) has no effect.

Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181

1 Answers1

4

By default, cells have borders in iText7 (0.5px solid black). So if you want to add a cell without border you should specify it by setting NO_BORDER as a cell border.

On the other hand, tables don't have borders by default, that's why table.setBorder(Border.NO_BORDER) has no effect on the resultant pdf.

So I'm afraid, but you should use the cell.setBorder(Border.NO_BORDER); approach.

As for adding a string to a cell: yes, one should add a paragraph now. The string-parameterized method was removed, because it wasn't quite clear how this string should be wrapped inside a cell

Uladzimir Asipchuk
  • 2,368
  • 1
  • 9
  • 19