pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1853465 - /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Date Tue, 12 Feb 2019 18:18:13 GMT
Author: tilman
Date: Tue Feb 12 18:18:13 2019
New Revision: 1853465

URL: http://svn.apache.org/viewvc?rev=1853465&view=rev
Log:
PDFBOX-4460: show URL or page destination in PDFDebugger on mouse move

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=1853465&r1=1853464&r2=1853465&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
Tue Feb 12 18:18:13 2019
@@ -47,7 +47,15 @@ import org.apache.pdfbox.rendering.PDFRe
 import org.apache.pdfbox.debugger.PDFDebugger;
 import org.apache.pdfbox.debugger.ui.HighResolutionImageIcon;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionURI;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
 import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 
@@ -84,19 +92,73 @@ public class PagePane implements ActionL
 
     private void initRectMap()
     {
-        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
-        if (acroForm == null)
+        try
+        {
+            collectFieldLocations();
+            collectLinkLocations();            
+        }
+        catch (IOException ex)
+        {
+            // ignore
+        }
+    }
+
+    private void collectLinkLocations() throws IOException
+    {
+        for (PDAnnotation annotation : page.getAnnotations())
         {
-            return;
+            if (annotation instanceof PDAnnotationLink)
+            {
+                PDAnnotationLink linkAnnotation = (PDAnnotationLink) annotation;
+                PDAction action = linkAnnotation.getAction();
+                if (action instanceof PDActionURI)
+                {
+                    PDActionURI uriAction = (PDActionURI) action;
+                    rectMap.put(annotation.getRectangle(), "URI: " + uriAction.getURI());
+                    continue;
+                }
+                PDDestination destination;
+                if (action instanceof PDActionGoTo)
+                {
+                    PDActionGoTo goToAction = (PDActionGoTo) action;
+                    destination = goToAction.getDestination();
+                }
+                else
+                {
+                    destination = linkAnnotation.getDestination();
+                }
+                if (destination instanceof PDNamedDestination)
+                {
+                    destination = document.getDocumentCatalog().
+                            findNamedDestinationPage((PDNamedDestination) destination);
+                }
+                if (destination instanceof PDPageDestination)
+                {
+                    PDPageDestination pageDestination = (PDPageDestination) destination;
+                    int pageNum = pageDestination.retrievePageNumber();
+                    if (pageNum != -1)
+                    {
+                        rectMap.put(annotation.getRectangle(), "Page destination: " + (pageNum
+ 1));
+                    }
+                }
+            }
         }
-        for (PDField field : acroForm.getFieldTree())
+    }
+
+    private void collectFieldLocations()
+    {
+        PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
+        if (acroForm != null)
         {
-            String fullyQualifiedName = field.getFullyQualifiedName();
-            for (PDAnnotationWidget widget : field.getWidgets())
+            for (PDField field : acroForm.getFieldTree())
             {
-                if (page.equals(widget.getPage()))
+                String fullyQualifiedName = field.getFullyQualifiedName();
+                for (PDAnnotationWidget widget : field.getWidgets())
                 {
-                    rectMap.put(widget.getRectangle(), fullyQualifiedName);
+                    if (page.equals(widget.getPage()))
+                    {
+                        rectMap.put(widget.getRectangle(), "Field name: " + fullyQualifiedName);
+                    }
                 }
             }
         }
@@ -246,7 +308,7 @@ public class PagePane implements ActionL
         {
             if (entry.getKey().contains(x1, y1))
             {
-                text += ", field: " + rectMap.get(entry.getKey());
+                text += ", " + rectMap.get(entry.getKey());
                 break;
             }
         }



Mime
View raw message