Cannot hide border of iText PDF Cell while putting a sub table into one parent PDFPCell

1.9k views Asked by At

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);
1

There are 1 answers

5
Chris Haas On BEST ANSWER

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);