首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenPDF:表不在页脚中

OpenPDF:表不在页脚中
EN

Stack Overflow用户
提问于 2020-05-21 15:53:28
回答 2查看 494关注 0票数 3

当我向页脚添加表时,页脚调整到合适的大小,然而,该表不停留在此页脚中,但是它将自己定位在页顶。

我创建了一个测试场景来说明我的意思。

代码语言:javascript
复制
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);
        }
    }
}

在本例中,页脚对表具有正确的大小:

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-08-03 18:18:24

这是OpenPDF的一个bug,现在应该已经修复了。https://github.com/LibrePDF/OpenPDF/issues/373

票数 0
EN

Stack Overflow用户

发布于 2022-05-22 17:34:45

您需要知道页面大小并从那里计算。

您可以使用

代码语言:javascript
复制
showTextAligned(ELEMENT.ALIGN_BOTTOM)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61938500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档