0

I am using itextpdf.text.pdf.PdfPTable for creating tables in PDF. But I cannot get rid of border of one pdfPcell. I have searched almost everywhere, but didn't get a solution. I can implement no border while i am using only below code-

    PdfPTable table_body = new PdfPTable(9);

    PdfPCell body_cell = new PdfPCell();
    body_cell.setBorder(Rectangle.NO_BORDER);


    PdfPCell body_cell = new PdfPCell();

    body_cell.setPhrase(new Phrase("Okey woth no border implementation"));
    table_body.addCell(body_cell);

But the issue is occurring while i am trying to put two rows in a single PdfPcell. What i am doing to achieve this, is i am creating another table and putting it to the parent table PDFPcell. But, the issue is one border is coming every time over the are of the parent table pdfPcell though i have defined PDFPcell to be without any border.

           body_cell.setPhrase(new Phrase("NOT Okey woth no border implementation"));

           PdfPTable sub_table = new PdfPTable(1);

           sub_table.addCell(body_cell);
           sub_table.addCell(body_cell);
           table_body.addCell(sub_table);

Added comment and code snippet below for further reference

Sorry.. But it is not working. I have tried trhis before. don't know if i am missing something. I have set defult border to no border and also at PDFCell level, i have set the border to none. Still getting a four side border around the sub table. Here is the code snippet:

PdfPTable sub_table = new PdfPTable(1);
sub_table.getDefaultCell().setBorder(Rectangle.NO_BORDER);

body_cell = new PdfPCell(image, true);
body_cell.setBorder(Rectangle.NO_BORDER);
sub_table.addCell(body_cell);
sub_table.addCell(body_cell_bottomBorder);
table_body.addCell(sub_table);
Ani
  • 87
  • 10
  • possible duplicate of [An invisible border of pdfptable](http://stackoverflow.com/questions/4900514/an-invisible-border-of-pdfptable) – Adrian B. Nov 25 '14 at 10:51

1 Answers1

2

When you are calling table_body.AddCell(sub_table) you are not explicitly creating a new cell but instead are leaving the defaults up to the system which is to have a border. You need to set the default cell's border to none if you want this to work.

table_body.getDefaultCell().setBorder(Rectangle.NO_BORDER);
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • Sorry.. But it is not working. I have tried trhis before. don't know if i am missing something. I have set defult border to no border and also at PDFCell level, i have set the border to none. Still getting a four side border around the sub table. Here is the code snippet: PdfPTable sub_table = new PdfPTable(1); sub_table.getDefaultCell().setBorder(Rectangle.NO_BORDER); body_cell = new PdfPCell(image, true); body_cell.setBorder(Rectangle.NO_BORDER); sub_table.addCell(body_cell); sub_table.addCell(body_cell_bottomBorder); table_body.addCell(sub_table); – Ani Nov 25 '14 at 15:39
  • 1
    You need to set the `NO_BORDER` on the outer table, in this case `table_body` – Chris Haas Nov 25 '14 at 16:08
  • Thank you very much Chris. that solved my issue. But i would request you to look at one more problem though it also may be a silly mistake again i am making. I have updated the question with the new problem. Thanks again. – Ani Nov 26 '14 at 13:39
  • Hi @Ani, this really would be better suited as a second question. Can you undo your edit and post another question? – Chris Haas Nov 26 '14 at 15:03
  • Hi Chris. Thank you for your help. I have put the new question in a different thread.I request you to have a look. thanks again. http://stackoverflow.com/questions/27155155/bottomborder-for-the-subtable-cell-and-for-the-general-pdfpcell-of-parent-table – Ani Nov 27 '14 at 09:12