public static PDSignatureField swapTextWithSignature(PDField box, List<PDField> fields) { PDSignatureField sig = null; try { PDAcroForm acroForm; acroForm = box.getAcroForm(); acroForm.getDictionary().setDirect(true); PDSignature sigobj = new PDSignature(); sig = new PDSignatureField(acroForm); sig.getDictionary().setDirect(true); sig.setSignature(sigobj); sig.getWidget().setPage(box.getWidget().getPage()); sig.setPartialName(box.getPartialName()); sig.setAlternateFieldName(box.getAlternateFieldName()); sig.getDictionary().setItem(COSName.RECT, box.getDictionary().getItem(COSName.RECT)); sig.getDictionary().setNeedToBeUpdate(true); acroForm.getDictionary().setInt(COSName.SIG_FLAGS, 3); acroForm.getDictionary().setNeedToBeUpdate(true); fields.remove(box); fields.add(sig); } catch (IOException ioe) { } return sig; }