Get page index of pdf page containing digital signature [closed]

送分小仙女□ 提交于 2021-01-29 11:00:34

问题


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?


回答1:


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));
                }
            }
        }
    }
}


来源:https://stackoverflow.com/questions/51530482/get-page-index-of-pdf-page-containing-digital-signature

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!