获取包含数字签名的pdf页面的页面索引 [英] Get page index of pdf page containing digital signature

查看:88
本文介绍了获取包含数字签名的pdf页面的页面索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取 PDF 文档中包含数字签名的页面的页面索引.如何使用 Apache PDFBox 获取它?

I have the requirement to get the page index of the page containing a digital signature in a pdf document. How can I get it using Apache PDFBox?

推荐答案

try (PDDocument doc = PDDocument.load(new File("....")))
{
    PDPageTree pageTree = doc.getPages();
    PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
    for (PDField field : acroForm.getFieldTree())  // null check omitted
    {
        if (field instanceof PDSignatureField)
        {
            PDSignatureField sigField = (PDSignatureField) field;
            for (PDAnnotationWidget widget : sigField.getWidgets())
            {
                PDPage page = widget.getPage();
                if (page != null)
                {
                    System.out.println("Signature on page " + (pageTree.indexOf(widget.getPage()) + 1));
                }
            }
        }
    }
}

这篇关于获取包含数字签名的pdf页面的页面索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆