An invisible border of pdfptable
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);
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, 2021Comments
-
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 about 10 yearsI tried both independently and both seem to make the border invisible. What exactly is the difference between
cellOne.setBorder(Rectangle.NO_BORDER);
andcellTwo.setBorder(Rectangle.BOX);
? -
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 over 9 years
Rectangle.NO_BORDER
is the same as0
I'd prefer to use the constants name, easier to read and always compatible when upgrading in version. -
Steven almost 9 yearsThis method does not appear to work in version 5.5.6. Sean's answer is correct: cellOne.setBorder(Rectangle.NO_BORDER);
-
mareckmareck over 8 yearsIt 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 over 5 yearsIf ItextSharp 5+ ; table.DefaultCell.BorderWidth = 0f works for the default cells only.
-
Artur INTECH about 2 yearsThis 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 about 2 yearsYou can define at table and cell
-
Artur INTECH about 2 yearsTechnically you can for some reason, but it has no effect. At least in Itext7.