Java IText中的表未添加正确的单元格
我正在Itext中创建一个文档,并将其分解为4个主单元格,其中嵌套了表。我正在创建文档的最后一个单元格,除了显示每行中的第一个单元格外,无法获取任何内容 这是我正在调用的函数,它返回一个我正在添加到主文档中的单元格Java IText中的表未添加正确的单元格,java,itext,Java,Itext,我正在Itext中创建一个文档,并将其分解为4个主单元格,其中嵌套了表。我正在创建文档的最后一个单元格,除了显示每行中的第一个单元格外,无法获取任何内容 这是我正在调用的函数,它返回一个我正在添加到主文档中的单元格 public PdfPCell getPSBioCell() { PdfPCell spaceCell = new PdfPCell(new Phrase("")); spaceCell.setColspan(1); // space spaceCell.s
public PdfPCell getPSBioCell() {
PdfPCell spaceCell = new PdfPCell(new Phrase(""));
spaceCell.setColspan(1); // space
spaceCell.setBorder(0);
PdfPTable table = new PdfPTable(4);
PdfPCell main = new PdfPCell();
noBorder(main);//
main.setPadding(0);//
PdfPCell dist = new PdfPCell(new Phrase(_rangerDistrict, nf));
PdfPCell district = new PdfPCell(new Phrase(this.sale.getRangerDistrict(), nf));
PdfPCell saleD = new PdfPCell(new Phrase(_saleDate, nf));
PdfPCell saleDate = new PdfPCell(new Phrase(this.formatDateString(sale.getSaleDate()), nf));
PdfPCell awardD = new PdfPCell(new Phrase(_awardDate, nf));
PdfPCell awardDate = new PdfPCell(new Phrase(this.formatDateString(sale.getAwardDate()), nf));
PdfPCell termD = new PdfPCell(new Phrase(_termDate, nf));
PdfPCell termDate = new PdfPCell(new Phrase(this.formatDateString(sale.getTerminationDate()), nf));
PdfPCell avg = new PdfPCell(new Phrase(_avgDbh , nf));
PdfPCell avgDbh = new PdfPCell(new Phrase(this.formatNumberString(String.valueOf(sale.getAveDiam())), nf));
PdfPCell cruis = new PdfPCell(new Phrase(_cruiser, nf));
PdfPCell cruiser = new PdfPCell(new Phrase(sale.getCruiser(), nf));
noBorder(dist, district, saleD, saleDate);
noBorder(awardD, awardDate, termD, termDate, avg);
noBorder(avgDbh, cruis, cruiser);
//
table.addCell(dist);
table.addCell(district);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(saleD);
table.addCell(saleDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(awardD);
table.addCell(awardDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(termD);
table.addCell(termDate);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(avg);
table.addCell(avgDbh);
table.addCell(spaceCell);
table.addCell(spaceCell);
//
table.addCell(cruis);
table.addCell(cruiser);
table.addCell(spaceCell);
table.addCell(spaceCell);
table.setWidthPercentage(100);
main.addElement(table);
return main;
}
这里的问题是在我的
noBorder(PdfPcell)
函数中,我正在做cell.setBorder(0)
,但我也在做cell.noWrap(true)
,所以将边框设置为0
,将noWrap设置为true
我看不到其他单元格被推离完整的Pdf页面 将您的代码更改为一个独立的示例,无需任何额外工作即可下载和执行,有人可能会看一看。现在,您刚刚粘贴了一些需要进行测试的代码,没有多少人有时间将其拼凑成一个独立的示例。你可能会认为这些人很懒惰,但要考虑到这些人可能会因为没有提供一个独立的例子而对你有同样的想法。毕竟:你的工作可能是有报酬的。人们在SO上的回答是没有报酬的。我看了一下代码,不得不说@Bruno是对的。代码中有太多未知因素(成员变量的值和方法调用的返回值),如果没有水晶球的额外输入,几乎不可能重现问题。