From 71a524bb5220555dd2d5ada468639c762d003ffe Mon Sep 17 00:00:00 2001 From: j-dimension Date: Tue, 22 Oct 2024 00:41:38 +0200 Subject: [PATCH] added support for multiple placeholders per PDF form field. close #2615 --- .../jlawyer/documents/PdfFormsAccess.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/PdfFormsAccess.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/PdfFormsAccess.java index 3569d3a37..2059ce66f 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/PdfFormsAccess.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/documents/PdfFormsAccess.java @@ -722,7 +722,7 @@ private static void list(PDField field, ArrayList 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")) { @@ -751,9 +751,9 @@ private static void replace(PDField field, HashMap 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); } @@ -788,11 +788,9 @@ private static void collectPlaceHolders(PDDocument document, ArrayList s List 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")) { @@ -829,9 +827,9 @@ private static PDDocument replacePlaceHolders(PDDocument document, HashMap