You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2019/06/19 16:32:22 UTC

svn commit: r1861642 - /pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java

Author: tilman
Date: Wed Jun 19 16:32:21 2019
New Revision: 1861642

URL: http://svn.apache.org/viewvc?rev=1861642&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/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java

Modified: pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1861642&r1=1861641&r2=1861642&view=diff
==============================================================================
--- pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java (original)
+++ pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java Wed Jun 19 16:32:21 2019
@@ -48,8 +48,10 @@ 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.Map.Entry;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import org.apache.pdfbox.debugger.ui.HighResolutionImageIcon;
@@ -162,14 +164,27 @@ public class PagePane implements ActionL
         {
             return;
         }
+        Set<COSDictionary> dictionarySet = new HashSet<>();
+        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());
                 }
             }
         }