private void addFieldString(PDField field) throws SAXException { // Pick partial name to present in content and altName for attribute // Ignoring FullyQualifiedName for now String partName = field.getPartialName(); String altName = field.getAlternateFieldName(); StringBuilder sb = new StringBuilder(); AttributesImpl attrs = new AttributesImpl(); if (partName != null) { sb.append(partName).append(": "); } if (altName != null) { attrs.addAttribute("", "altName", "altName", "CDATA", altName); } // return early if PDSignature field if (field instanceof PDSignatureField) { handleSignature(attrs, (PDSignatureField) field); return; } String value = field.getValueAsString(); if (value != null && !value.equals("null")) { sb.append(value); } if (attrs.getLength() > 0 || sb.length() > 0) { xhtml.startElement("li", attrs); xhtml.characters(sb.toString()); xhtml.endElement("li"); } }
@Override void importFDF(FDFField fdfField) throws IOException { super.importFDF(fdfField); List<FDFField> fdfKids = fdfField.getKids(); List<PDField> children = getChildren(); for (int i = 0; fdfKids != null && i < fdfKids.size(); i++) { for (COSObjectable pdKid : children) { if (pdKid instanceof PDField) { PDField pdChild = (PDField) pdKid; FDFField fdfChild = fdfKids.get(i); String fdfName = fdfChild.getPartialFieldName(); if (fdfName != null && fdfName.equals(pdChild.getPartialName())) { pdChild.importFDF(fdfChild); } } } } }
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; }