/** * This method determines if the given field is a button. * * @param field the field to determine * @return the result of the determination * @throws IOException If there is an error determining the field type. */ private static boolean isButton(PDField field) throws IOException { String ft = field.findFieldType(); boolean retval = FIELD_TYPE_BTN.equals(ft); List kids = field.getKids(); if (ft == null && kids != null && kids.size() > 0) { // sometimes if it is a button the type is only defined by one // of the kids entries Object obj = kids.get(0); COSDictionary kidDict = null; if (obj instanceof PDField) { kidDict = ((PDField) obj).getDictionary(); } else if (obj instanceof PDAnnotationWidget) { kidDict = ((PDAnnotationWidget) obj).getDictionary(); } else { throw new IOException("Error:Unexpected type of kids field:" + obj); } retval = isButton(new PDUnknownField(field.getAcroForm(), kidDict)); } return retval; }
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; }