检索Java中的PDF签名表单字段的坐标

时间:2019-02-14 20:57:41

标签: java pdf pdfbox openpdf

我想知道如何使用PDFBOX或OpenPDF检索PDF中签名表单字段的坐标。输入的PDF包含经过数字签名的电子签名。

期待您的帮助。

1 个答案:

答案 0 :(得分:1)

占位符对我来说是未签名的签名,但是您提到了签名字段。但我为您写了两种针对openPDF的解决方案:

PdfReader reader = new PdfReader(...)
AcroFields fields = reader.getAcroFields();
//unsigned signatures
//ArrayList<String> al = fields.getBlankSignatureNames();
//signed signatures
ArrayList<String> al = fields.getSignatureNames();     

for (int i = 0; i < al.size(); i++) {

 String fieldName = al.get(i);
 float[] position = fields.getFieldPositions(fieldName);

 //assuming that signatures doesn't have several widgets. (like it can be for other fields)
 for(int i=0;i<position.length;i+=5){
    int pageNumber = (int) position[0];
    float lowerLeftX = position[1]; 
    float lowerLeftY = position[2];
    float upperRightX = position[3];
    float upperRightY = position[4];
    System.out.println("llx:"+lowerLeftX+" lly:"+lowerLeftY+" urx:"+upperRightX+" ury: "upperRightY);
 }