pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1642742 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java
Date Mon, 01 Dec 2014 19:40:08 GMT
Author: lehmi
Date: Mon Dec  1 19:40:08 2014
New Revision: 1642742

URL: http://svn.apache.org/r1642742
Log:
PDFBOX-2525: added the usage of PDDocuments as input

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java   (contents, props
changed)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java?rev=1642742&r1=1642741&r2=1642742&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java Mon Dec  1 19:40:08
2014
@@ -68,13 +68,28 @@ public class Overlay
     private Position position = Position.BACKGROUND;
 
     private String inputFileName = null;
+    private PDDocument inputPDFDocument = null;
+
     private String outputFilename = null;
+    
     private String defaultOverlayFilename = null;
+    private PDDocument defaultOverlay = null;
+
     private String firstPageOverlayFilename = null;
+    private PDDocument firstPageOverlay = null;
+
     private String lastPageOverlayFilename = null;
+    private PDDocument lastPageOverlay = null;
+    
     private String allPagesOverlayFilename = null;
+    private PDDocument allPagesOverlay = null;
+    
     private String oddPageOverlayFilename = null;
+    private PDDocument oddPageOverlay = null;
+    
     private String evenPageOverlayFilename = null;
+    private PDDocument evenPageOverlay = null;
+
     
     private int numberOfOverlayPages = 0;
     private boolean useAllOverlayPages = false;
@@ -83,68 +98,30 @@ public class Overlay
      * This will add overlays to a documents.
      * 
      * @param specificPageOverlayFile map of overlay files for specific pages
+     * @param useNonSeqParser indicates whether the non-sequential parser is used
      * @throws IOException if something went wrong
      */
     public void overlay(Map<Integer, String> specificPageOverlayFile)
             throws IOException
     {
-        PDDocument sourcePDFDocument = null;
-        PDDocument defaultOverlay = null;
-        PDDocument firstPageOverlay = null;
-        PDDocument lastPageOverlay = null;
-        PDDocument allPagesOverlay = null;
-        PDDocument oddPageOverlay = null;
-        PDDocument evenPageOverlay = null;
         try
         {
-            sourcePDFDocument = loadPDF(inputFileName);
-            if (defaultOverlayFilename != null)
-            {
-                defaultOverlay = loadPDF(defaultOverlayFilename);
-                defaultOverlayPage = getLayoutPage(defaultOverlay);
-            }
-            if (firstPageOverlayFilename != null)
-            {
-                firstPageOverlay = loadPDF(firstPageOverlayFilename);
-                firstPageOverlayPage = getLayoutPage(firstPageOverlay);
-            }
-            if (lastPageOverlayFilename != null)
-            {
-                lastPageOverlay = loadPDF(lastPageOverlayFilename);
-                lastPageOverlayPage = getLayoutPage(lastPageOverlay);
-            }
-            if (oddPageOverlayFilename != null)
-            {
-                oddPageOverlay = loadPDF(oddPageOverlayFilename);
-                oddPageOverlayPage = getLayoutPage(oddPageOverlay);
-            }
-            if (evenPageOverlayFilename != null)
-            {
-                evenPageOverlay = loadPDF(evenPageOverlayFilename);
-                evenPageOverlayPage = getLayoutPage(evenPageOverlay);
-            }
-            if (allPagesOverlayFilename != null)
-            {
-                allPagesOverlay = loadPDF(allPagesOverlayFilename);
-                specificPageOverlayPage = getLayoutPages(allPagesOverlay);
-                useAllOverlayPages = true;
-                numberOfOverlayPages = specificPageOverlayPage.size();
-            }
+            loadPDFs();
             for (Map.Entry<Integer, String> e : specificPageOverlayFile.entrySet())
             {
                 PDDocument doc = loadPDF(e.getValue());
                 specificPageOverlay.put(e.getKey(), doc);
                 specificPageOverlayPage.put(e.getKey(), getLayoutPage(doc));
             }
-            processPages(sourcePDFDocument);
+            processPages(inputPDFDocument);
 
-            sourcePDFDocument.save(outputFilename);
+            inputPDFDocument.save(outputFilename);
         }
         finally
         {
-            if (sourcePDFDocument != null)
+            if (inputPDFDocument != null)
             {
-                sourcePDFDocument.close();
+                inputPDFDocument.close();
             }
             if (defaultOverlay != null)
             {
@@ -179,6 +156,71 @@ public class Overlay
         }
     }
 
+    private void loadPDFs() throws IOException
+    {
+        // input PDF
+        if (inputFileName != null)
+        {
+            inputPDFDocument = loadPDF(inputFileName);
+        }
+        // default overlay PDF
+        if (defaultOverlayFilename != null)
+        {
+            defaultOverlay = loadPDF(defaultOverlayFilename);
+        }
+        if (defaultOverlay != null)
+        {
+            defaultOverlayPage = getLayoutPage(defaultOverlay);
+        }
+        // first page overlay PDF
+        if (firstPageOverlayFilename != null)
+        {
+            firstPageOverlay = loadPDF(firstPageOverlayFilename);
+        }
+        if (firstPageOverlay != null)
+        {
+            firstPageOverlayPage = getLayoutPage(firstPageOverlay);
+        }
+        // last page overlay PDF
+        if (lastPageOverlayFilename != null)
+        {
+            lastPageOverlay = loadPDF(lastPageOverlayFilename);
+        }
+        if (lastPageOverlay != null)
+        {
+            lastPageOverlayPage = getLayoutPage(lastPageOverlay);
+        }
+        // odd pages overlay PDF
+        if (oddPageOverlayFilename != null)
+        {
+            oddPageOverlay = loadPDF(oddPageOverlayFilename);
+        }
+        if (oddPageOverlay != null)
+        {
+            oddPageOverlayPage = getLayoutPage(oddPageOverlay);
+        }
+        // even pages overlay PDF
+        if (evenPageOverlayFilename != null)
+        {
+            evenPageOverlay = loadPDF(evenPageOverlayFilename);
+        }
+        if (evenPageOverlay != null)
+        {
+            evenPageOverlayPage = getLayoutPage(evenPageOverlay);
+        }
+        // all pages overlay PDF
+        if (allPagesOverlayFilename != null)
+        {
+            allPagesOverlay = loadPDF(allPagesOverlayFilename);
+        }
+        if (allPagesOverlay != null)
+        {
+            specificPageOverlayPage = getLayoutPages(allPagesOverlay);
+            useAllOverlayPages = true;
+            numberOfOverlayPages = specificPageOverlayPage.size();
+        }
+    }
+    
     private PDDocument loadPDF(String pdfName) throws IOException
     {
         return PDDocument.load(new File(pdfName));
@@ -228,7 +270,8 @@ public class Overlay
             {
                 resources = new PDResources();
             }
-            layoutPages.put(i,new LayoutPage(page.getMediaBox(), createContentStream(contents),
resources.getCOSObject()));
+            layoutPages.put(i,new LayoutPage(page.getMediaBox(), createContentStream(contents),

+                    resources.getCOSObject()));
         }
         return layoutPages;
     }
@@ -437,6 +480,16 @@ public class Overlay
     }
 
     /**
+     * Sets the PDF to be overlayed.
+     * 
+     * @param inputPDF the PDF to be overlayed
+     */
+    public void setInputPDF(PDDocument inputPDF)
+    {
+        inputPDFDocument = inputPDF;
+    }
+
+    /**
      * Returns the input file.
      * 
      * @return the input file
@@ -477,6 +530,16 @@ public class Overlay
     }
 
     /**
+     * Sets the default overlay PDF.
+     * 
+     * @param defaultOverlayPDF the default overlay PDF
+     */
+    public void setDefaultOverlayPDF(PDDocument defaultOverlayPDF)
+    {
+        defaultOverlay = defaultOverlayPDF;
+    }
+
+    /**
      * Returns the default overlay file.
      * 
      * @return the default overlay file
@@ -497,6 +560,16 @@ public class Overlay
     }
 
     /**
+     * Sets the first page overlay PDF.
+     * 
+     * @param firstPageOverlayPDF the first page overlay PDF
+     */
+    public void setFirstPageOverlayPDF(PDDocument firstPageOverlayPDF)
+    {
+        firstPageOverlay = firstPageOverlayPDF;
+    }
+
+    /**
      * Sets the last page overlay file.
      * 
      * @param lastPageOverlayFile the last page overlay file
@@ -507,6 +580,16 @@ public class Overlay
     }
 
     /**
+     * Sets the last page overlay PDF.
+     * 
+     * @param lastPageOverlayPDF the last page overlay PDF
+     */
+    public void setLastPageOverlayPDF(PDDocument lastPageOverlayPDF)
+    {
+        lastPageOverlay = lastPageOverlayPDF;
+    }
+
+    /**
      * Sets the all pages overlay file.
      * 
      * @param allPagesOverlayFile the all pages overlay file
@@ -517,6 +600,16 @@ public class Overlay
     }
 
     /**
+     * Sets the all pages overlay PDF.
+     * 
+     * @param allPagesOverlayPDF the all pages overlay PDF
+     */
+    public void setAllPagesOverlayPDF(PDDocument allPagesOverlayPDF)
+    {
+        allPagesOverlay = allPagesOverlayPDF;
+    }
+
+    /**
      * Sets the odd page overlay file.
      * 
      * @param oddPageOverlayFile the odd page overlay file
@@ -527,6 +620,16 @@ public class Overlay
     }
 
     /**
+     * Sets the odd page overlay PDF.
+     * 
+     * @param oddPageOverlayPDF the odd page overlay PDF
+     */
+    public void setOddPageOverlayPDF(PDDocument oddPageOverlayPDF)
+    {
+        oddPageOverlay = oddPageOverlayPDF;
+    }
+
+    /**
      * Sets the even page overlay file.
      * 
      * @param evenPageOverlayFile the even page overlay file
@@ -536,4 +639,13 @@ public class Overlay
         evenPageOverlayFilename = evenPageOverlayFile;
     }
 
+    /**
+     * Sets the even page overlay PDF.
+     * 
+     * @param evenPageOverlayPDF the even page overlay PDF
+     */
+    public void setEvenPageOverlayPDF(PDDocument evenPageOverlayPDF)
+    {
+        evenPageOverlay = evenPageOverlayPDF;
+    }
 }

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Dec  1 19:40:08 2014
@@ -0,0 +1,3 @@
+/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java:1642737
+/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java:1618517-1621410
+/pdfbox/no-awt/pdfbox/src/main/java/org/apache/pdfbox/util/Overlay.java:1618514-1618516



Mime
View raw message