Please give a brief summary of your issue:
Unable to test if signature fields have been signed
Please describe your issue and provide steps to reproduce it:
I have a form with a number of different field types on it. Some are signature fields. Even when the signature fields have been signed, I get “nil” values for them when I iterate over all the fields on the form. I need a way to test if a signature field has been signed.
Please provide a link to a minimal sample where the issue is reproducible:
Open a form with a signature field in a PTDocumentController.
Sign that field
Iterate over the fields on the form and try to get the value for that signature.
guard let formFieldIterator = self.document?.getFieldIterator() else
{
return
}
while formFieldIterator.hasNext()
{
let field: PTField = formFieldIterator.current()
let fv = field.getValue()
let ft = field.getType()
print("name = \(String(describing: field.getName())) /// type = \(ft) /// val = \(String(describing: fv))")
formFieldIterator.next()
}
To check if the field is signed with an appearance, you can use digsigfield.hasVisibleAppearance(). To check if it’s signed with a certificate, you can use digsigfield.hasCryptographicSignature(). Note that the digsigfield is an instance of PTDigitalSignatureField, which you can create from a regular PTField.
Also possibly useful is the method signatureState in the file PTDigitalSignature.m from the Tools.framework code (included with the .dmg download), which I’ve pasted here for convenience:
-(PTDigitalSignatureState)signatureState
{
@try {
[self.pdfViewCtrl DocLockRead];
PTWidget *widget = [[PTWidget alloc] initWithAnn:self.currentAnnotation];
PTField *field = [widget GetField];
if( [field GetType] != e_ptsignature )
{
return -1;
}
PTDigitalSignatureField* digSigField = [[PTDigitalSignatureField alloc] initWithIn_field:field];
if ( [digSigField HasCryptographicSignature] )
{
return PTDigitalSignatureStateDigitallySigned;
}
if( [digSigField HasVisibleAppearance] == NO )
{
return PTDigitalSignatureStateEmpty;
}
PTObj *appearance = [self.currentAnnotation GetAppearance:e_ptnormal app_state:0];
PTElementReader *reader = [[PTElementReader alloc] init];
// when the element reader is destroyed so is the element that it returned. It is therefore important
// important to keep the reader alive until finished with the element
PTElement *element = [self getFirstElementUsingReader:reader fromObj:appearance ofType:e_ptform];
PTObj* xobj = [element GetXObject];
if( [xobj IsValid] )
{
PTElementReader* objReader = [[PTElementReader alloc] init];
[objReader ReaderBeginWithSDFObj:xobj resource_dict:nil ocg_context:nil];
for(PTElement* el = [objReader Next]; el != 0; el = [objReader Next])
{
if( [el GetType] == e_ptpath )
{
return PTDigitalSignatureStatePathAppearanceOnly;
}
if( [el GetType] == e_ptimage )
{
return PTDigitalSignatureStateImageAppearanceOnly;
}
}
}
}
@catch (NSException *exception) {
NSLog(@"Exception: %@: %@", exception.name, exception.reason);
}
@finally {
[self.pdfViewCtrl DocUnlockRead];
}
return PTDigitalSignatureStateEmpty;
}