pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1780227 - in /pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger: PDFDebugger.java pagepane/PagePane.java ui/DocumentEntry.java ui/PageEntry.java
Date Wed, 25 Jan 2017 16:34:24 GMT
Author: tilman
Date: Wed Jan 25 16:34:24 2017
New Revision: 1780227

URL: http://svn.apache.org/viewvc?rev=1780227&view=rev
Log:
PDFBOX-2941: show page label when available

Modified:
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DocumentEntry.java
    pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PageEntry.java

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java?rev=1780227&r1=1780226&r2=1780227&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
(original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/PDFDebugger.java
Wed Jan 25 16:34:24 2017
@@ -101,6 +101,7 @@ import org.apache.pdfbox.debugger.ui.Rot
 import org.apache.pdfbox.debugger.ui.Tree;
 import org.apache.pdfbox.debugger.ui.ZoomMenu;
 import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.common.PDPageLabels;
 import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
 import org.apache.pdfbox.printing.PDFPageable;
 
@@ -1359,4 +1360,33 @@ public class PDFDebugger extends JFrame
         System.err.println(message);
         System.exit(1);
     }
+
+    /**
+     * Convenience method to get the page label if available.
+     * 
+     * @param document
+     * @param pageIndex 0-based page number.
+     * @return a page label or null if not available.
+     */
+    static public String getPageLabel(PDDocument document, int pageIndex)
+    {
+        PDPageLabels pageLabels;
+        try
+        {
+            pageLabels = document.getDocumentCatalog().getPageLabels();
+        }
+        catch (IOException ex)
+        {
+            return ex.getMessage();
+        }
+        if (pageLabels != null)
+        {
+            String[] labels = pageLabels.getLabelsByPageIndices();
+            if (labels[pageIndex] != null)
+            {
+                return labels[pageIndex];
+            }
+        }
+        return null;
+    }
 }

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=1780227&r1=1780226&r2=1780227&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 Jan 25 16:34:24 2017
@@ -41,6 +41,7 @@ import org.apache.pdfbox.debugger.ui.Zoo
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.rendering.PDFRenderer;
+import org.apache.pdfbox.debugger.PDFDebugger;
 
 /**
  * Display the page number and a page rendering.
@@ -74,7 +75,14 @@ public class PagePane implements ActionL
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
         String pageLabelText = pageIndex < 0 ? "Page number not found" : "Page " + (pageIndex
+ 1);
-        
+
+        // append PDF page label, if available
+        String lbl = PDFDebugger.getPageLabel(document, pageIndex);
+        if (lbl != null)
+        {
+            pageLabelText += " - " + lbl;
+        }
+
         JLabel pageLabel = new JLabel(pageLabelText);
         pageLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
         pageLabel.setFont(new Font(Font.MONOSPACED, Font.BOLD, 30));

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DocumentEntry.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DocumentEntry.java?rev=1780227&r1=1780226&r2=1780227&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DocumentEntry.java
(original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/DocumentEntry.java
Wed Jan 25 16:34:24 2017
@@ -19,6 +19,7 @@ package org.apache.pdfbox.debugger.ui;
 
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.debugger.PDFDebugger;
 
 /**
  * Represents an abstract view of a document in the tree view.
@@ -44,7 +45,8 @@ public class DocumentEntry
     public PageEntry getPage(int index)
     {
         PDPage page = doc.getPages().get(index);
-        return new PageEntry(page.getCOSObject(), index + 1);
+        String pageLabel = PDFDebugger.getPageLabel(doc, index);
+        return new PageEntry(page.getCOSObject(), index + 1, pageLabel);
     }
     
     public int indexOf(PageEntry page)

Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PageEntry.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PageEntry.java?rev=1780227&r1=1780226&r2=1780227&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PageEntry.java
(original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/ui/PageEntry.java
Wed Jan 25 16:34:24 2017
@@ -30,11 +30,13 @@ public class PageEntry
 {
     private final COSDictionary dict;
     private final int pageNum;
-    
-    public PageEntry(COSDictionary page, int pageNum)
+    private final String pageLabel;    
+
+    public PageEntry(COSDictionary page, int pageNum, String pageLabel)
     {
         dict = page;
         this.pageNum = pageNum;
+        this.pageLabel = pageLabel;
     }
     
     public COSDictionary getDict()
@@ -50,7 +52,7 @@ public class PageEntry
     @Override
     public String toString()
     {
-        return "Page: " + pageNum;
+        return "Page: " + pageNum + (pageLabel == null ? "" : " - " + pageLabel);
     }
     
     public String getPath()



Mime
View raw message