diff options
| author | Thomas Lenz <thomas.lenz@a-sit.at> | 2026-01-13 15:03:55 +0000 |
|---|---|---|
| committer | Thomas Lenz <thomas.lenz@a-sit.at> | 2026-01-13 15:03:55 +0000 |
| commit | 04b752f38832e309d96392f0c1a3a6e02de55edc (patch) | |
| tree | 1a755efc3f7a4d1f3fab9d6445662c89c8467f32 /pdf-as-pdfbox-2/src/main/java | |
| parent | 26c64ac5e251d359c8ca958150e76b0d9f0da78f (diff) | |
| parent | ae290f93ab4aa310709168cd684008b5c898087a (diff) | |
| download | pdf-as-4-04b752f38832e309d96392f0c1a3a6e02de55edc.tar.gz pdf-as-4-04b752f38832e309d96392f0c1a3a6e02de55edc.tar.bz2 pdf-as-4-04b752f38832e309d96392f0c1a3a6e02de55edc.zip | |
Merge branch 'feature/placeholder_fix' into 'development'
chore(placeholder): update internal placeholderId generation to support old version too
See merge request egiz/pdf-as-4!13
Diffstat (limited to 'pdf-as-pdfbox-2/src/main/java')
| -rw-r--r-- | pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java index 8716603b..e954b654 100644 --- a/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java +++ b/pdf-as-pdfbox-2/src/main/java/at/gv/egiz/pdfas/lib/impl/pdfbox2/placeholder/SignaturePlaceholderExtractor.java @@ -245,7 +245,13 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl try { data.setTablePos(new TablePos(posString)); - data.setPlaceholderName(buildUniqueObjectName(objectName)); + + boolean idExists = placeholders.stream() + .filter(el -> el.getPlaceholderName().equals(objectName.getName())) + .findFirst() + .isPresent(); + + data.setPlaceholderName(buildUniqueObjectName(objectName, idExists)); log.debug("Found Placeholder at: {}", data.toString()); placeholders.add(data); @@ -272,10 +278,13 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl private static String readPlaceHolderId(PDSignature signature) { PDPropBuild sigProps = getOrNew(signature); PDPropBuildDataDict appProps = getOrNew(sigProps); - return appProps.getName() != null && appProps.getName().startsWith(PREFIX) + String newHolderId = appProps.getName() != null && appProps.getName().startsWith(PREFIX) ? appProps.getName().substring(PREFIX.length()) : appProps.getName(); + // read placeHolderId from old location element as backup + return newHolderId != null ? newHolderId : signature.getLocation(); + } /** @@ -297,25 +306,22 @@ public class SignaturePlaceholderExtractor extends PDFStreamEngine implements Pl * Builds unique placeholderId from PDF element. * * @param name PDF element name + * @param idExists <code>true</code> if same name already found, otherwise false * @return unique identifier */ - private String buildUniqueObjectName(COSName name) - { + private String buildUniqueObjectName(COSName name, boolean idExists) { + if (idExists) { COSDictionary dict = getResources().getCOSObject().getCOSDictionary(COSName.XOBJECT); - if (dict == null) - { - return name.getName(); - - } - - COSBase base = dict.getItem(name); - if (base instanceof COSObject) - { + if (dict != null) { + COSBase base = dict.getItem(name); + if (base instanceof COSObject) { return name.getName() + "_" + String.valueOf(((COSObject) base).getObjectNumber()); + } } + } - return name.getName(); + return name.getName(); } |
