// Distinction of case for visual and non-visual signature
if (visualSignature == null) // non-visual signature
{
// Set rectangle for non-visual signature to 0 0 0 0
signatureField.getWidget().setRectangle(new PDRectangle()); // rectangle array [ 0 0 0 0 ]
// Clear AcroForm / Set DefaultRessource
acroFormDict.setItem(COSName.DR, null);
// Set empty Appearance-Dictionary
PDAppearanceDictionary ap = new PDAppearanceDictionary();
COSStream apsStream = getDocument().createCOSStream();
apsStream.createUnfilteredStream();
PDAppearanceStream aps = new PDAppearanceStream(apsStream);
COSDictionary cosObject = (COSDictionary)aps.getCOSObject();
cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
cosObject.setItem(COSName.BBOX, new PDRectangle());
ap.setNormalAppearance(aps);
ap.getDictionary().setDirect(true);
signatureField.getWidget().setAppearance(ap);
}
else // visual signature
{
// Obtain visual signature object
List<COSObject> cosObjects = visualSignature.getObjects();
boolean annotNotFound = true;
boolean sigFieldNotFound = true;
for ( COSObject cosObject : cosObjects )
{
if (!annotNotFound && !sigFieldNotFound)
{
break;
}
COSBase base = cosObject.getObject();
if (base != null && base instanceof COSDictionary)
{
COSBase ft = ((COSDictionary)base).getItem(COSName.FT);
COSBase type = ((COSDictionary)base).getItem(COSName.TYPE);
COSBase apDict = ((COSDictionary)base).getItem(COSName.AP);
// Search for signature annotation
if (annotNotFound && COSName.ANNOT.equals(type))
{
COSDictionary cosBaseDict = (COSDictionary)base;
// Read and set the Rectangle for visual signature
COSArray rectAry = (COSArray)cosBaseDict.getItem(COSName.RECT);
PDRectangle rect = new PDRectangle(rectAry);
signatureField.getWidget().setRectangle(rect);
annotNotFound = false;
}
// Search for Signature-Field