pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1861639 - /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Date Wed, 19 Jun 2019 16:32:06 GMT
Author: tilman
Date: Wed Jun 19 16:32:06 2019
New Revision: 1861639

URL: http://svn.apache.org/viewvc?rev=1861639&view=rev
Log:
PDFBOX-2941: improve detection of widget annotations by checking whether field widget annotation
is in the list of page annotations, because widget.getPage() is sometimes null, see bottom
fields in the file of poppler issue 778

Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1861639&r1=1861638&r2=1861639&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
(original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Wed Jun 19 16:32:06 2019
@@ -29,7 +29,9 @@ import java.awt.geom.AffineTransform;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import javax.swing.BoxLayout;
 import javax.swing.JLabel;
@@ -152,14 +154,27 @@ public class PagePane implements ActionL
         {
             return;
         }
+        Set<COSDictionary> dictionarySet = new HashSet<COSDictionary>();
+        try
+        {
+            for (PDAnnotation annotation : page.getAnnotations())
+            {
+                dictionarySet.add(annotation.getCOSObject());
+            }
+        }
+        catch (IOException ex)
+        {
+            return;
+        }
         for (PDField field : acroForm.getFieldTree())
         {
-            String fullyQualifiedName = field.getFullyQualifiedName();
             for (PDAnnotationWidget widget : field.getWidgets())
             {
-                if (page.equals(widget.getPage()))
+                // check if the annotation widget is on this page
+                // (checking widget.getPage() also works, but it is sometimes null)
+                if (dictionarySet.contains(widget.getCOSObject()))
                 {
-                    rectMap.put(widget.getRectangle(), "Field name: " + fullyQualifiedName);
+                    rectMap.put(widget.getRectangle(), "Field name: " + field.getFullyQualifiedName());
                 }
             }
         }



Mime
View raw message