An invisible border of pdfptable

90,385

Solution 1

The Border Elements of the PdfPTable are defined by the PdfPCell which are added to the table. Each Cell will have its own style/formatting. Here is the API: http://api.itextpdf.com/

Example

PdfPTable table = new PdfPTable(2);
PdfPCell cellOne = new PdfPCell(new Phrase("Hello"));
PdfPCell cellTwo = new PdfPCell(new Phrase("World"));

cellOne.setBorder(Rectangle.NO_BORDER);
cellOne.setBackgroundColor(new Color(255,255,45));

cellTwo.setBorder(Rectangle.BOX);

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

If you want more detail about the Rectangle/Border values, take a look at the IText Constant values section for Rectangle, here : http://api.itextpdf.com/constant-values.html

Solution 2

In my app it works like this:

PdfPTable table = new PdfPTable(2);
table.getDefaultCell().setBorder(0);
...

Solution 3

The below works for me.

table.getDefaultCell().setBorderWidth(0f);

Solution 4

    PdfPTable nestedTable = new PdfPTable();
    nestedTable.DefaultCell.Border = 0;

    nestedTable.AddCell(new Phrase("First");
    nestedTable.AddCell(new Phrase("Second");
    nestedTable.AddCell(new Phrase("2515");

    PdfPCell nestCell= new PdfPCell(nestedTable);

Solution 5

you can hide the border like this

PdfPCell cell = new PdfPCell ();
cell.setBorder(Rectangle.NO_BORDER);
Share:
90,385
yogsma
Author by

yogsma

Programmer. Founder of https://rentersvoices.com Developer of Android Application YFormulator (formerly Formulator). I used to write posts for Java Code Geeks here. Now I write better java code. Also you can check my github repositories github. You can download my ebook Spring Boot and Microservices Certified Scrum Master

Updated on April 28, 2021

Comments

  • yogsma
    yogsma about 3 years

    I am using iText library for generating pdf files in Java. I am writing data in pdfptable , how can I make the borders of table invisible?

  • Qohelet
    Qohelet about 10 years
    I tried both independently and both seem to make the border invisible. What exactly is the difference between cellOne.setBorder(Rectangle.NO_BORDER); and cellTwo.setBorder(Rectangle.BOX);?
  • wmdvanzyl
    wmdvanzyl almost 10 years
    nestedTable.DefaultCell.Border = 0; - that just doesn't look right. Upon testing i also found that doesn't work. Unless the DefaultCell and Border properties are public this could never work.
  • chillworld
    chillworld over 9 years
    Rectangle.NO_BORDER is the same as 0 I'd prefer to use the constants name, easier to read and always compatible when upgrading in version.
  • Steven
    Steven almost 9 years
    This method does not appear to work in version 5.5.6. Sean's answer is correct: cellOne.setBorder(Rectangle.NO_BORDER);
  • mareckmareck
    mareckmareck over 8 years
    It could work - but only in C# (seeing the case of Properties and Method calls), while OP asked about Java solution. Also, there are parenthesis missing in lines 4-6.
  • Anass
    Anass over 5 years
    If ItextSharp 5+ ; table.DefaultCell.BorderWidth = 0f works for the default cells only.
  • Artur INTECH
    Artur INTECH about 2 years
    This will not work. "Borders are defined at the level of the cell, not at the level of the table. Hence if you want to remove the borders of the table, you need to remove the borders of each cell". kb.itextpdf.com/home/it7kb/faq/…
  • Kevin Montalvo
    Kevin Montalvo about 2 years
    You can define at table and cell
  • Artur INTECH
    Artur INTECH about 2 years
    Technically you can for some reason, but it has no effect. At least in Itext7.