0

我正在使用 itextpdf.text.pdf.PdfPTable 以 PDF 格式创建表格。但我无法摆脱一个 pdfPcell 的边框。我几乎在所有地方都进行了搜索,但没有找到解决方案。当我只使用下面的代码时,我可以实现无边框 -

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

但是当我试图将两行放在一个 PdfPcell 中时,问题就出现了。我正在做什么来实现这一点,我正在创建另一个表并将其放入父表 PDFPcell。但是,问题是每次在父表 pdfPcell 的区域上都会出现一个边框,尽管我已将 PDFPcell 定义为没有任何边框。

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

在下面添加了注释和代码片段以供进一步参考

对不起..但它不工作。我以前试过tris。不知道我是否遗漏了什么。我已将默认边框设置为无边框,并且在 PDFCell 级别,我已将边框设置为无边框。子表周围仍然有一个四边边框。这是代码片段:

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

1 回答 1

2

当你打电话时,table_body.AddCell(sub_table)你并没有明确地创建一个新的单元格,而是将默认值留给有边框的系统。如果你想让它工作,你需要将默认单元格的边框设置为无。

table_body.getDefaultCell().setBorder(Rectangle.NO_BORDER);
于 2014-11-25T14:47:44.167 回答