Refine search
PDFormFieldAdditionalActions aa = field.getActions(); if (aa != null) List<PDAnnotationWidget> widgets = field.getWidgets(); if (res && widgets != null) return exploreWidgets(ctx, field.getWidgets());
private void acroFormLegacyMode(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm) throws IOException List<PDField> srcFields = srcAcroForm.getFields(); COSArray destFields; final int prefixLength = prefix.length(); for (PDField destField : destAcroForm.getFieldTree()) String fieldName = destField.getPartialName(); if (fieldName.startsWith(prefix)) COSBase base = destAcroForm.getCOSObject().getItem(COSName.FIELDS); if (base instanceof COSArray) for (PDField srcField : srcAcroForm.getFields()) COSDictionary dstField = (COSDictionary) cloner.cloneForNewDocument(srcField.getCOSObject()); if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)
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 public String toString() { return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: " + getInheritableAttribute(COSName.V) + "}"; } }
// Load the pdfTemplate pdfTemplate = PDDocument.load(file); PDDocumentCatalog docCatalog = pdfTemplate.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm(); // Get field names List<PDField> fieldList = acroForm.getFields(); // String the object array String[] fieldArray = new String[fieldList.size()]; int i = 0; for (PDField sField : fieldList) { fieldArray[i] = sField.getFullyQualifiedName(); i++; } // Loop through each field in the array and do something for (String f : fieldArray) { PDField field = acroForm.getField(f); System.out.println("f is: " + f); if (f.contains("EXAMPLE FORM FIELD NAME")) { DO SOMETHING String value = "example value"; field.setValue(value); System.out.println("printed: " + value + " to: " + f); } } // Save edited file pdfTemplate.save(sPdfTemplate); pdfTemplate.close();
@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); } } } } }
if (signature != null) rect = acroForm.getField(signatureFieldName).getWidgets().get(0).getRectangle(); if (acroForm != null && acroForm.getNeedAppearances()) if (acroForm.getFields().isEmpty())
/** * Generate a unique name for the signature. * * @return the signature's unique name */ private String generatePartialName() { String fieldName = "Signature"; Set<String> sigNames = new HashSet<>(); // fixme: this ignores non-terminal fields, so will miss any descendant signatures for (PDField field : getAcroForm().getFields()) { if(field instanceof PDSignatureField) { sigNames.add(field.getPartialName()); } } int i = 1; while(sigNames.contains(fieldName+i)) { ++i; } return fieldName+i; }
PDField field = acroForm.getField("SampleField"); PDAnnotationWidget widget = field.getWidgets().get(0); field.getActions().getCOSObject().addAll(fieldActions.getCOSObject());
void removeFormfield( PDField field ) throws IOException { PDAcroForm acroForm = field.getAcroForm(); List<PDField> acroFields = acroForm.getFields(); List<PDField> removeCandidates = getFields( acroFields, field.getPartialName() ); if( removeAll( acroFields, removeCandidates ) ) acroForm.setFields( acroFields ); }
private void initRectMap() { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); if (acroForm == null) { return; } for (PDField field : acroForm.getFieldTree()) { String fullyQualifiedName = field.getFullyQualifiedName(); for (PDAnnotationWidget widget : field.getWidgets()) { if (page.equals(widget.getPage())) { rectMap.put(widget.getRectangle(), fullyQualifiedName); } } } }
/** * This will get a field by name, possibly using the cache if setCache is true. * * @param fullyQualifiedName The name of the field to get. * @return The field with that name of null if one was not found. */ public PDField getField(String fullyQualifiedName) { // get the field from the cache if there is one. if (fieldCache != null) { return fieldCache.get(fullyQualifiedName); } // get the field from the field tree for (PDField field : getFieldTree()) { if (field.getFullyQualifiedName().equals(fullyQualifiedName)) { return field; } } return null; }
PDField field = acroForm.getField("SampleField"); PDAnnotationWidget widget = field.getWidgets().get(0); font = acroForm.getDefaultResources().getFont(fontName);
public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) { PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm(); // Get the field and the widget associated to it. // Note: there might be multiple widgets PDField field = acroForm.getField("SampleField"); PDAnnotationWidget widget = field.getWidgets().get(0); // Create the definition for a green border PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary()); PDColor green = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE); fieldAppearance.setBorderColour(green); // Set the information to be used by the widget which is responsible // for the visual style of the form field. widget.setAppearanceCharacteristics(fieldAppearance); document.save("target/AddBorderToField.pdf"); } } }
for (PDField field : (List<PDField>)acroForm.getFields()) { COSDictionary fieldDict = field.getDictionary(); List<COSObjectable> kids = field.getKids(); if (kids != null) { for (COSObjectable kid : kids) { System.out.printf("i Field '%s' not referenced (invisible).\n", field.getFullyQualifiedName()); else System.out.printf("a Field '%s' referenced by separate annotation on %s.\n", field.getFullyQualifiedName(), annotationPages); else if (annotationPages.isEmpty()) System.out.printf("m Field '%s' referenced as merged on %s.\n", field.getFullyQualifiedName(), mergedPage); else System.out.printf("x Field '%s' referenced as merged on %s and by separate annotation on %s. (Not allowed!)\n", field.getFullyQualifiedName(), mergedPage, annotationPages);
List<PDAnnotationWidget> widgets = field.getWidgets(); for (PDAnnotationWidget widget : widgets)
private void processField(PDField field, String sLevel, String sParent) throws IOException String partialName = field.getPartialName(); if (!sParent.equals(field.getPartialName())) String fieldValue = field.getValueAsString(); StringBuilder outputString = new StringBuilder(sLevel); outputString.append(sParent);
/** * Returns the fully qualified name of the field, which is a concatenation of the names of all the parents fields. * * @return the name of the field */ public String getFullyQualifiedName() { String finalName = getPartialName(); String parentName = parent != null ? parent.getFullyQualifiedName() : null; if (parentName != null) { if (finalName != null) { finalName = parentName + "." + finalName; } else { finalName = parentName; } } return finalName; }
List<COSObjectable> kids = field.getKids(); if (kids != null) { for (COSObjectable pdfObj : kids) { String partialName = field.getPartialName().replaceAll("\\[\\d\\]", ""); if (!(field instanceof PDSignatureField) && values.containsKey(partialName)) { field.setValue(values.get(partialName));
private List<PDAction> getAdditionalAction() { PDFormFieldAdditionalActions pbActions = ((PDField) this.simplePDObject) .getActions(); if (pbActions != null) { List<PDAction> actions = new ArrayList<>(MAX_NUMBER_OF_ACTIONS); org.apache.pdfbox.pdmodel.interactive.action.PDAction buffer; buffer = pbActions.getC(); this.addAction(actions, buffer); buffer = pbActions.getF(); this.addAction(actions, buffer); buffer = pbActions.getK(); this.addAction(actions, buffer); buffer = pbActions.getV(); this.addAction(actions, buffer); return Collections.unmodifiableList(actions); } return Collections.emptyList(); }