英文:
Remove nested table border from itext table
问题
String dest = FileSystems.getDefault().getPath("").toAbsolutePath().toString() + "/test.pdf";
log.info(dest);
PdfWriter writer = new PdfWriter(dest);
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.addNewPage();
Document document = new Document(pdfDoc);
float[] pointColumnWidths = {150F, 150F};
Table outerTable = new Table(pointColumnWidths);
for (int i = 0; i < 5; i++) {
outerTable.addCell("col1-" + i);
outerTable.addCell("col2-" + i);
}
float[] innerTablePointColumnWidths = {150F, 150F, 150F, 150F};
Table nestedTable = new Table(innerTablePointColumnWidths);
nestedTable.addCell("col11");
nestedTable.addCell("col11_val");
nestedTable.addCell("col12");
nestedTable.addCell("col12_val");
nestedTable.addCell("col22");
nestedTable.addCell("col22_val");
nestedTable.addCell("col23");
nestedTable.addCell("col23_val");
nestedTable.addCell("col31");
nestedTable.addCell("col31_val");
nestedTable.addCell("col32");
nestedTable.addCell("col32_val");
outerTable.addCell("nestedParent");
outerTable.setBorder(Border.NO_BORDER);
/* Cell cell = new Cell();
cell.add(nestedTable);*/
// cell.setBorder(Border.NO_BORDER);
// outerTable.addCell(cell);
outerTable.addCell(nestedTable);
document.add(outerTable);
document.close();
itext相关库版本 7.1.12
英文:
I was trying to create nested table in itext by java. I can create it but unexpectedly, the nested table holds its own border along with the original table's cell border.
Is there any way to remove the outer border only of the nested table, in nestedParent's right column?
My code:
String dest= FileSystems.getDefault().getPath("").toAbsolutePath().toString()+"/test.pdf";
log.info(dest);
PdfWriter writer= new PdfWriter(dest);
PdfDocument pdfDoc = new PdfDocument(writer);
pdfDoc.addNewPage();
Document document = new Document(pdfDoc);
float [] pointColumnWidths = {150F, 150F};
Table outerTable = new Table(pointColumnWidths);
for (int i = 0; i < 5; i++) {
outerTable.addCell("col1-" + i);
outerTable.addCell("col2-" + i);
}
float [] innerTablePointColumnWidths = {150F, 150F, 150F, 150F};
Table nestedTable = new Table(innerTablePointColumnWidths);
nestedTable.addCell("col11");
nestedTable.addCell("col11_val");
nestedTable.addCell("col12");
nestedTable.addCell("col12_val");
nestedTable.addCell("col22");
nestedTable.addCell("col22_val");
nestedTable.addCell("col23");
nestedTable.addCell("col23_val");
nestedTable.addCell("col31");
nestedTable.addCell("col31_val");
nestedTable.addCell("col32");
nestedTable.addCell("col32_val");
outerTable.addCell("nestedParent");
outerTable.setBorder(Border.NO_BORDER);
/* Cell cell = new Cell();
cell.add(nestedTable);*/
// cell.setBorder(Border.NO_BORDER);
//outerTable.addCell(cell);
outerTable.addCell(nestedTable);
document.add(outerTable);
document.close();
itext related lib version 7.1.12
答案1
得分: 0
你需要从内部表格单元中移除每个边框(即"col11"单元格应将其上边和左边的边框设置为null或Border#NO_BORDER,并将内部表格单元格也设置为null)。
此外,您还应将内部表格的填充设置为0以消除间隙。
Cell cell = new Cell();
cell.setPadding(0);
cell.add(nestedTable);
outerTable.addCell(cell);
英文:
You need to remove each border from the inner table cells (i.e "col11" cell should set his upper and left border to null or Border#NO_BORDER AND set the inner table cell to null as well).
Furthermore, You should set the padding of the inner table to 0 in order to remove the gap.
Cell cell = new Cell();
cell.setPadding(0);
cell.add(nestedTable);
outerTable.addCell(cell);
答案2
得分: 0
我无法使用内部表格解决这个问题。所以,为了解决这个问题,我不得不定义一个包含5列的表格,然后在必要时为该特定条目定义所需的单元格定义,使用 row
和 col
span
,就像下面这样:
Cell cell = new Cell(1, 1);
Cell cell = new Cell(1, 4);
对于行内的五列:
Cell cell = new Cell(4, 1);
这样就解决了!
英文:
I couldn't solve the problem using inner table. So, to solve that, I have to define a table of 5 columns and then when necessary I have defined the necessary cell definition for that particular entry, using row
and col
span
, like
Cell cell= new Cell(1,1);
Cell cell=new Cell(1,4);
For five columns inside a row:
Cell cell= new Cell(4,1)
this way it is solved!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论