我正在创建一个包含多个表格的 PDF 文档,当表格只有一行时,它不会将其添加到文档中。当我在另一篇文章中看到这一点时,我检查了该行是否已完成,并添加了table.completeRow()以防万一。然而,它工作的唯一方法是添加另一个空行:
table.addCell(new Paragraph("", paragraphFontNormal));
table.completeRow()
我不认为这是一个很好的解决方案,我想知道这里出了什么问题。有人可以帮忙吗?
这是方法:
public void createPdf(DateRange dates, HttpServletResponse response) throws DocumentException, IOException {
boolean first = true;
Document document = new Document(PageSize.A4.rotate());
PdfWriter.getInstance(document, response.getOutputStream());
document.open();
List<Rejects> report = findAll(dates);
for(Rejects rejects : report){
if (first) {
first = false;
addGroupAdmin(rejects, document, dates);
}else{
if (rejects.getAdminGroup().equals(adminGroup)) {
table.addCell(new Paragraph(rejects.getZone(), paragraphFontNormal));
table.addCell(new Paragraph(dateFormat.format(rejects.getRejDate()), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getProcName(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getKindId(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getVarietyName(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getSlrn(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getRejReason(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getAdminGroup(), paragraphFontNormal));
table.addCell(new Paragraph(rejects.getDescription(), paragraphFontNormal));
}else{
/*** It doesn't work like this for one row***/
document.add(table);
document.newPage();
addGroupAdmin(rejects, document, dates);
}
}
}
拉风的咖菲猫
相关分类