@Override public String toString() { return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: " + getInheritableAttribute(COSName.V) + "}"; } }
/** * This will tell this form to cache the fields into a Map structure * for fast access via the getField method. The default is false. You would * want this to be false if you were changing the COSDictionary behind the scenes, * otherwise setting this to true is acceptable. * * @param cache A boolean telling if we should cache the fields. */ public void setCacheFields(boolean cache) { if (cache) { fieldCache = new HashMap<>(); for (PDField field : getFieldTree()) { fieldCache.put(field.getFullyQualifiedName(), field); } } else { fieldCache = null; } }
/** * 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; }
// 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();
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); } } } }
if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)
List<PDField> alFields = acroForm.getFields(); for(PDField f:alFields){ System.out.println(f.getFullyQualifiedName()); }
@Override public String toString() { return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: " + getInheritableAttribute(COSName.V) + "}"; } }
//PDFBox API doesn't include generics for PDAcroForm.getFields(); //type-cast should always be safe @SuppressWarnings("unchecked") List<PDField> fields = form.getFields(); String v; for (PDField field : fields) { v = field.getValue(); values.put(field.getFullyQualifiedName(), v == null ? "" : v); }
public void list(PDField field) { System.out.println(field.getFullyQualifiedName() + " (" + field.getClass().getName() +")"); if(field instanceof PDRadioButton){ System.out.println("Radio Button"); System.out.println(((PDRadioButton) field).getOnValues()); } }
@SuppressWarnings("unchecked") List<PDField> fields = acroForm.getFields(); for (PDField field : fields) { if (field.getFullyQualifiedName().equals("formfield1")) { field.setReadOnly(true); } }
@Override public String toString() { return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: " + getInheritableAttribute(COSName.V) + "}"; } }
/** * This will tell this form to cache the fields into a Map structure * for fast access via the getField method. The default is false. You would * want this to be false if you were changing the COSDictionary behind the scenes, * otherwise setting this to true is acceptable. * * @param cache A boolean telling if we should cache the fields. */ public void setCacheFields(boolean cache) { if (cache) { fieldCache = new HashMap<String, PDField>(); for (PDField field : getFieldTree()) { fieldCache.put(field.getFullyQualifiedName(), field); } } else { fieldCache = null; } }
/** * 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; }
/** * This will tell this form to cache the fields into a Map structure * for fast access via the getField method. The default is false. You would * want this to be false if you were changing the COSDictionary behind the scenes, * otherwise setting this to true is acceptable. * * @param cache A boolean telling if we should cache the fields. */ public void setCacheFields(boolean cache) { if (cache) { fieldCache = new HashMap<>(); for (PDField field : getFieldTree()) { fieldCache.put(field.getFullyQualifiedName(), field); } } else { fieldCache = null; } }
/** * 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; }
List<String> getFormFieldNames(PDDocument pdDocument) { PDAcroForm pdAcroForm = pdDocument.getDocumentCatalog().getAcroForm(); if (pdAcroForm == null) return Collections.emptyList(); List<String> result = new ArrayList<>(); for (PDField pdField : pdAcroForm.getFieldTree()) { if (pdField instanceof PDTerminalField) { result.add(pdField.getFullyQualifiedName()); } } return result; }
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);
if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)
if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)