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 2018/09/08 09:00:24 UTC

svn commit: r1840347 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Author: tilman
Date: Sat Sep  8 09:00:24 2018
New Revision: 1840347

URL: http://svn.apache.org/viewvc?rev=1840347&view=rev
Log:
PDFBOX-4298: allow pages without content stream, as suggested by Mikita Geer

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java?rev=1840347&r1=1840346&r2=1840347&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/multipdf/Overlay.java Sat Sep  8 09:00:24 2018
@@ -261,7 +261,7 @@ public class Overlay
         {
             resources = new PDResources();
         }
-        return new LayoutPage(page.getMediaBox(), createContentStream(contents),
+        return new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents),
                 resources.getCOSObject());
     }
     
@@ -278,13 +278,13 @@ public class Overlay
             {
                 resources = new PDResources();
             }
-            layoutPages.put(i,new LayoutPage(page.getMediaBox(), createContentStream(contents), 
+            layoutPages.put(i, new LayoutPage(page.getMediaBox(), createCombinedContentStream(contents), 
                     resources.getCOSObject()));
         }
         return layoutPages;
     }
     
-    private COSStream createContentStream(COSBase contents) throws IOException
+    private COSStream createCombinedContentStream(COSBase contents) throws IOException
     {
         List<COSStream> contentStreams = createContentStreamList(contents);
         // concatenate streams
@@ -301,10 +301,15 @@ public class Overlay
         return concatStream;
     }
 
+    // get the content streams as a list
     private List<COSStream> createContentStreamList(COSBase contents) throws IOException
     {
         List<COSStream> contentStreams = new ArrayList<COSStream>();
-        if (contents instanceof COSStream)
+        if (contents == null)
+        {
+            return contentStreams;
+        }
+        else if (contents instanceof COSStream)
         {
             contentStreams.add((COSStream) contents);
         }
@@ -321,7 +326,7 @@ public class Overlay
         }
         else
         {
-            throw new IOException("Contents are unknown type:" + contents.getClass().getName());
+            throw new IOException("Unknown content type: " + contents.getClass().getName());
         }
         return contentStreams;
     }
@@ -366,6 +371,11 @@ public class Overlay
 
     private void addOriginalContent(COSBase contents, COSArray contentArray) throws IOException
     {
+        if (contents == null)
+        {
+            return;
+        }
+
         if (contents instanceof COSStream)
         {
             contentArray.add(contents);
@@ -376,8 +386,7 @@ public class Overlay
         }
         else
         {
-            throw new IOException("Unknown content type: " +
-                    (contents == null ? "(null)" : contents.getClass().getName()));
+            throw new IOException("Unknown content type: " + contents.getClass().getName());
         }
     }