Skip to content

Commit

Permalink
added support for multiple placeholders per PDF form field. close #2615
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Oct 21, 2024
1 parent a719876 commit 71a524b
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ private static void list(PDField field, ArrayList<String> searchStrings, ArrayLi

for (String ph : searchStrings) {
// placeholders may be VALUES of a form field or may be the NAME of a form field
if (field.getValueAsString() != null && field.getValueAsString().equals(ph)) {
if (field.getValueAsString() != null && field.getValueAsString().contains(ph)) {
foundStrings.add(ph);
} else {
if (field.getCOSObject().containsKey("TU")) {
Expand Down Expand Up @@ -751,9 +751,9 @@ private static void replace(PDField field, HashMap<String, Object> values) {
}

// placeholders may be VALUES of a form field or may be the NAME of a form field
if (field.getValueAsString() != null && field.getValueAsString().equals(key)) {
if (field.getValueAsString() != null && field.getValueAsString().contains(key)) {
try {
field.setValue(values.get(key).toString());
field.setValue(field.getValueAsString().replace(key, values.get(key).toString()));
} catch (IOException ex) {
log.error("Error setting placeholder " + key + " in PDF form", ex);
}
Expand Down Expand Up @@ -788,11 +788,9 @@ private static void collectPlaceHolders(PDDocument document, ArrayList<String> s
List<PDField> fields = form.getFields();

for (PDField field : fields) {
System.out.println("Feld (Name = Wert): " + field.getFullyQualifiedName() + " = " + field.getValueAsString());

for (String ph : searchStrings) {
// placeholders may be VALUES of a form field or may be the NAME of a form field
if (field.getValueAsString() != null && field.getValueAsString().equals(ph)) {
if (field.getValueAsString() != null && field.getValueAsString().contains(ph)) {
foundStrings.add(ph);
} else {
if (field.getCOSObject().containsKey("TU")) {
Expand Down Expand Up @@ -829,9 +827,9 @@ private static PDDocument replacePlaceHolders(PDDocument document, HashMap<Strin
}

// placeholders may be VALUES of a form field or may be the NAME of a form field
if (field.getValueAsString() != null && field.getValueAsString().equals(key)) {
if (field.getValueAsString() != null && field.getValueAsString().contains(key)) {
try {
field.setValue(values.get(key).toString());
field.setValue(field.getValueAsString().replace(key, values.get(key).toString()));
} catch (IOException ex) {
log.error("Error setting placeholder " + key + " in PDF form", ex);
}
Expand Down

0 comments on commit 71a524b

Please sign in to comment.