static long getSignatureOffset(File pdfFile) throws PDFNetException {
PDFDoc pdfDoc = new PDFDoc(pdfFile.getPath());
try {
Field field = pdfDoc.getField("Signature1");
DictIterator dictIterator = field.getSDFObj().getDictIterator();
while (dictIterator.hasNext() == true) {
dictIterator.next();
if (dictIterator.key() != null) {
String key = dictIterator.key().getName();
System.out.println(key);
if ("V".equals(key)) {
Obj value = dictIterator.value();
Obj contents = value.findObj("Contents");
System.out.println("type=" + contents.getType());
System.out.println("offset=" + contents.getOffset());
return Long.valueOf(contents.getOffset());
// findByteRange(" ", "/" + key, dictIterator.value());
}
}
}
return 0;
} finally {
pdfDoc.close();
}
}
----------------------------------------------------
A:
Your code is yielding the correct value. The digital signature dict is located in the xref table at the offset
98876. If you have cosedit.exe as part of the SDK you downloaded (which
should be the case if you're using a Windows version of the SDK), then
you can see it at that offset (object number 54).
According to the PDF Reference, the ByteRange array is an array of
pairs of integers (starting byte offset, length in bytes) describing the
exact byte range for the digest calculation. Multiple discontiguous
byte ranges are used to describe a digest that does not include the
signature value (the Contents entry) itself. So 98953 is just a value
in the ByteRange array referring to the scope of the signature's digest
calculation.