在我的代码中,我根据随机值将随机单元格添加到表中
这是我的代码
Document document = new Document(PageSize.LETTER.rotate());
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
document.setMargins(16, 14, 14, 14);
document.open();
PdfPTable table = new PdfPTable(2);
table.setTotalWidth(document.right() - document.left());
table.setLockedWidth(true);
PdfPCell headerCell = new PdfPCell();
headerCell.addElement(new Phrase("Header 1"));
table.addCell(headerCell);
headerCell = new PdfPCell();
headerCell.addElement(new Phrase("Header 2"));
table.addCell(headerCell);
PdfPCell footerCell = new PdfPCell();
footerCell.addElement(new Phrase("Footer"));
footerCell.setColspan(2);
table.addCell(footerCell);
table.setHeaderRows(2);
table.setFooterRows(1);
table.setSkipLastFooter(true);
int count = 0;
int randomValue = getRandom();
for (int i = 0; i <= 1500; i++) {
if (count == randomValue) {
PdfPCell randomCell = new PdfPCell();
randomCell.addElement(new Phrase("Random Value : " + randomValue));
randomCell.setColspan(2);
table.addCell(randomCell);
count = 0;
randomValue = getRandom();
} else {
table.addCell("Cell " + i);
table.addCell("Cell " + i);
++count;
}
}
document.add(table);
document.close();
在某些页面中,有时,随机单元格位于标题单元格的正下方,这是我要避免的。我希望它出现在上一页中,所以新页面仅从普通单元格开始,如何实现?
我正在附上问题的屏幕截图