/** * Search acroform fields for signature field with specific signature dictionary. * * @param fieldIterator iterator on all fields. * @param sigObject signature object (the /V part). * @return a signature field if found, or null if none was found. */ private PDSignatureField findSignatureField(Iterator<PDField> fieldIterator, PDSignature sigObject) { PDSignatureField signatureField = null; while (fieldIterator.hasNext()) { PDField pdField = fieldIterator.next(); if (pdField instanceof PDSignatureField) { PDSignature signature = ((PDSignatureField) pdField).getSignature(); if (signature != null && signature.getCOSObject().equals(sigObject.getCOSObject())) { signatureField = (PDSignatureField) pdField; } } } return signatureField; }
/** * Extracts last Document-Signature from the document. The signature will be set on the signature-field. * * @param document to get the Signature from * @throws IOException */ private void getRelevantSignature(PDDocument document) throws IOException { // we can't use getLastSignatureDictionary() because this will fail (see PDFBOX-3978) // if a signature is assigned to a pre-defined empty signature field that isn't the last. // we get the last in time by looking at the offset in the PDF file. SortedMap<Integer, PDSignature> sortedMap = new TreeMap<>(); for (PDSignature sig : document.getSignatureDictionaries()) { int sigOffset = sig.getByteRange()[1]; sortedMap.put(sigOffset, sig); } if (sortedMap.size() > 0) { PDSignature lastSignature = sortedMap.get(sortedMap.lastKey()); COSBase type = lastSignature.getCOSObject().getItem(COSName.TYPE); if (type.equals(COSName.SIG)) { signature = lastSignature; } } }
/** * Gets the last relevant signature in the document, i.e. the one with the highest offset. * * @param document to get its last signature * @return last signature or null when none found * @throws IOException */ public static PDSignature getLastRelevantSignature(PDDocument document) throws IOException { SortedMap<Integer, PDSignature> sortedMap = new TreeMap<>(); for (PDSignature signature : document.getSignatureDictionaries()) { int sigOffset = signature.getByteRange()[1]; sortedMap.put(sigOffset, signature); } if (sortedMap.size() > 0) { PDSignature lastSignature = sortedMap.get(sortedMap.lastKey()); COSBase type = lastSignature.getCOSObject().getItem(COSName.TYPE); if (type.equals(COSName.SIG) || type.equals(COSName.DOC_TIME_STAMP)) { return lastSignature; } } return null; } }
if (sig.getCOSObject().isNeedToBeUpdated())
COSDictionary sigDict = sig.getCOSObject(); COSString contents = (COSString) sigDict.getDictionaryObject(COSName.CONTENTS);
/** * Search acroform fields for signature field with specific signature dictionary. * * @param fieldIterator iterator on all fields. * @param sigObject signature object (the /V part). * @return a signature field if found, or null if none was found. */ private PDSignatureField findSignatureField(Iterator<PDField> fieldIterator, PDSignature sigObject) { PDSignatureField signatureField = null; while (fieldIterator.hasNext()) { PDField pdField = fieldIterator.next(); if (pdField instanceof PDSignatureField) { PDSignature signature = ((PDSignatureField) pdField).getSignature(); if (signature != null && signature.getCOSObject().equals(sigObject.getCOSObject())) { signatureField = (PDSignatureField) pdField; } } } return signatureField; }
sigObject.getCOSObject().setNeedToBeUpdated(true);
/** * Search acroform fields for signature field with specific signature dictionary. * * @param fieldIterator iterator on all fields. * @param sigObject signature object (the /V part). * @return a signature field if found, or null if none was found. */ private PDSignatureField findSignatureField(Iterator<PDField> fieldIterator, PDSignature sigObject) { PDSignatureField signatureField = null; while (fieldIterator.hasNext()) { PDField pdField = fieldIterator.next(); if (pdField instanceof PDSignatureField) { PDSignature signature = ((PDSignatureField) pdField).getSignature(); if (signature != null && signature.getCOSObject().equals(sigObject.getCOSObject())) { signatureField = (PDSignatureField) pdField; } } } return signatureField; }
private List<PDSigRef> getSigRefs() { COSArray reference = (COSArray) ((org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature) this.simplePDObject).getCOSObject().getDictionaryObject(REFERENCE); if (reference == null || reference.size() == 0) { return Collections.emptyList(); } List<PDSigRef> list = new ArrayList<>(); for (COSBase sigRef : reference) { list.add(new PBoxPDSigRef((COSDictionary) sigRef, this.document)); } return Collections.unmodifiableList(list); } }
/** * Gets the last relevant signature in the document, i.e. the one with the highest offset. * * @param document to get its last signature * @return last signature or null when none found * @throws IOException */ public static PDSignature getLastRelevantSignature(PDDocument document) throws IOException { SortedMap<Integer, PDSignature> sortedMap = new TreeMap<Integer, PDSignature>(); for (PDSignature signature : document.getSignatureDictionaries()) { int sigOffset = signature.getByteRange()[1]; sortedMap.put(sigOffset, signature); } if (sortedMap.size() > 0) { PDSignature lastSignature = sortedMap.get(sortedMap.lastKey()); COSBase type = lastSignature.getCOSObject().getItem(COSName.TYPE); if (type.equals(COSName.SIG) || type.equals(COSName.DOC_TIME_STAMP)) { return lastSignature; } } return null; } }
/** * Extracts last Document-Signature from the document. The signature will be set on the * signature-field. * * @param document to get the Signature from * @throws IOException */ private void getRelevantSignature(PDDocument document) throws IOException { // we can't use getLastSignatureDictionary() because this will fail (see PDFBOX-3978) // if a signature is assigned to a pre-defined empty signature field that isn't the last. // we get the last in time by looking at the offset in the PDF file. SortedMap<Integer, PDSignature> sortedMap = new TreeMap<Integer, PDSignature>(); for (PDSignature sig : document.getSignatureDictionaries()) { int sigOffset = sig.getByteRange()[1]; sortedMap.put(sigOffset, sig); } if (sortedMap.size() > 0) { PDSignature lastSignature = sortedMap.get(sortedMap.lastKey()); COSBase type = lastSignature.getCOSObject().getItem(COSName.TYPE); if (type.equals(COSName.SIG)) { signature = lastSignature; } } }
COSDictionary sigDict = signature.getCOSObject();
for (PDSignature sig : document.getSignatureDictionaries()) COSDictionary sigDict = sig.getCOSObject(); COSString contents = (COSString) sigDict.getDictionaryObject(COSName.CONTENTS);
if (sig.getCOSObject().isNeedToBeUpdated())
if (sig.getCOSObject().isNeedToBeUpdated())
sigObject.getCOSObject().setNeedToBeUpdated(true);
sigObject.getCOSObject().setNeedToBeUpdated(true);
COSDictionary sigDict = signature.getCOSObject();