当我向页脚添加表时,页脚调整到合适的大小,然而,该表不停留在此页脚中,但是它将自己定位在页顶。
我创建了一个测试场景来说明我的意思。
public class TestClass {
public static void main(String[] args) {
try {
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("fail.pdf"));
PdfPTable table = new PdfPTable(2);
table.setWidthPercentage(100);
table.addCell(new PdfPCell(new Paragraph("CONTENT")));
table.addCell(new PdfPCell(new Paragraph("CONTENT")));
Paragraph footerParagraph = new Paragraph();
footerParagraph.add(table);
HeaderFooter footer = new HeaderFooter(footerParagraph, false);
footer.setAlignment(Element.ALIGN_CENTER);
document.setFooter(footer);
document.open();
document.add(new Paragraph("Hello World"));
document.close();
} catch (Exception ex) {
System.out.println(ex);
}
}
}在本例中,页脚对表具有正确的大小:

然而,如前所述,表不在底部,而是在顶部:

发布于 2022-08-03 18:18:24
这是OpenPDF的一个bug,现在应该已经修复了。https://github.com/LibrePDF/OpenPDF/issues/373
发布于 2022-05-22 17:34:45
您需要知道页面大小并从那里计算。
您可以使用
showTextAligned(ELEMENT.ALIGN_BOTTOM)https://stackoverflow.com/questions/61938500
复制相似问题