]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Addes Linking to a specific page and a named destinations of an
authorChristian Geisert <chrisg@apache.org>
Wed, 16 Oct 2002 17:01:56 +0000 (17:01 +0000)
committerChristian Geisert <chrisg@apache.org>
Wed, 16 Oct 2002 17:01:56 +0000 (17:01 +0000)
external PDF file (see www.adobe.com/products/acrobat/pdfs/c01acrotip.pdf)
Submitted by: Bernd Brandstetter <bbrand@freenet.de>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195332 13f79535-47bb-0310-9956-ffa450edef68

docs/examples/fo/link.fo
src/org/apache/fop/pdf/PDFDocument.java
src/org/apache/fop/pdf/PDFGoToRemote.java
status.xml

index 28ab1b31efb66f706240b147e929c066167d9d76..e44efcc27fec3cd8bac17582bc057e9ea384c104 100644 (file)
                                go to <fo:basic-link external-destination="normal.pdf">normal.pdf</fo:basic-link>
                        </fo:block>
 
+                       <!-- Normal text -->
+                       <fo:block text-align="start"
+                                                               space-before.optimum="6pt"
+                                                               line-height="24pt"
+                                                               font-family="serif"
+                                                               padding-top="3pt"
+                                                               >
+                               9. Linking to a specific page of an external:
+                               <fo:basic-link external-destination="extensive.pdf#page=1">extensive.pdf, Page 2</fo:basic-link>.
+                       </fo:block>
 
                        <!-- Normal text -->
 <!--      <fo:block text-align="start"
index e483b6791c56d43fb0efbce6ccef1e85c8273f67..8dd9c0c86094a1e6a5f5d0fa243e039f37bd6702 100644 (file)
@@ -1233,6 +1233,7 @@ public class PDFDocument {
 
         PDFLink linkObject;
         PDFAction action;
+        int index;
 
         PDFLink link = new PDFLink(++this.objectcount, rect);
         this.objects.add(link);
@@ -1246,6 +1247,22 @@ public class PDFDocument {
                 action = new PDFGoToRemote(++this.objectcount, fileSpec);
                 this.objects.add(action);
                 link.setAction(action);
+            } else if ((index = destination.indexOf(".pdf#page=")) > 0) {
+                String file = destination.substring(0, index + 4);
+                int page = Integer.parseInt(destination.substring(index + 10));
+                PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file);
+                this.objects.add(fileSpec);
+                action = new PDFGoToRemote(++this.objectcount, fileSpec, page);
+                this.objects.add(action);
+                link.setAction(action);
+            } else if ((index = destination.indexOf(".pdf#dest=")) > 0) {
+                String file = destination.substring(0, index + 4);
+                String dest = destination.substring(index + 10);
+                PDFFileSpec fileSpec = new PDFFileSpec(++this.objectcount, file);
+                this.objects.add(fileSpec);
+                action = new PDFGoToRemote(++this.objectcount, fileSpec, dest);
+                this.objects.add(action);
+                link.setAction(action);
             } else {                               // URI
                 PDFUri uri = new PDFUri(destination);
                 link.setAction(uri);
index aa8ef5afa7f868891b34ad8aa151816d298fa5b1..ad102034cb671fd5071566b14d651a3c744bcd16 100644 (file)
@@ -16,6 +16,8 @@ public class PDFGoToRemote extends PDFAction {
      * the file specification
      */
     protected PDFFileSpec pdfFileSpec;
+    protected int pageReference = 0;
+    protected String destination = null;
 
     /**
      * create an GoToR object.
@@ -31,6 +33,38 @@ public class PDFGoToRemote extends PDFAction {
         this.pdfFileSpec = pdfFileSpec;
     }
 
+    /**
+     * create an GoToR object.
+     *
+     * @param number the object's number
+     * @param fileSpec the fileSpec associated with the action
+     * @param page a page reference within the remote document
+     */
+    public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, int page) {
+
+        /* generic creation of object */
+        super(number);
+
+        this.pdfFileSpec = pdfFileSpec;
+        this.pageReference = page;
+    }
+
+    /**
+     * create an GoToR object.
+     *
+     * @param number the object's number
+     * @param fileSpec the fileSpec associated with the action
+     * @param dest a named destination within the remote document
+     */
+    public PDFGoToRemote(int number, PDFFileSpec pdfFileSpec, String dest) {
+
+        /* generic creation of object */
+        super(number);
+
+        this.pdfFileSpec = pdfFileSpec;
+        this.destination = dest;
+    }
+
     /**
      * return the action string which will reference this object
      *
@@ -48,9 +82,16 @@ public class PDFGoToRemote extends PDFAction {
     public byte[] toPDF() {
         String p = new String(this.number + " " + this.generation + " obj\n"
                               + "<<\n/S /GoToR\n" + "/F "
-                              + pdfFileSpec.referencePDF() + "\n"
-                              + "/D [ 0 /XYZ null null null ]"
-                              + " \n>>\nendobj\n");
+                              + pdfFileSpec.referencePDF() + "\n");
+
+        if (destination != null) {
+            p += "/D (" + this.destination + ")";
+        } else {
+            p += "/D [ " + this.pageReference + " /XYZ null null null ]";
+        }
+
+        p += " \n>>\nendobj\n";
+
         return p.getBytes();
     }
 
index ee6aef97ba5dbb3dec40c8cdd0c740cc3c73fe7e..b364b4585445447b90857e5b405eb8e6c1c5c802 100644 (file)
@@ -123,6 +123,12 @@ inactive??
 
   <changes>
    <release version="?" date="2002">
+    <action dev="CG" type="add" context="code"
+            due-to="Bernd Brandstetter" due-to-email="bbrand@freenet.de">
+      Linking to a specific page and a named destinations of an
+      external PDF file.
+      (see www.adobe.com/products/acrobat/pdfs/c01acrotip.pdf)
+    </action>
     <action context="code" dev="KLL" type="update">
       Started table layout managers.
     </action>