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 2016/06/19 11:53:46 UTC

svn commit: r1749155 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Author: tilman
Date: Sun Jun 19 11:53:46 2016
New Revision: 1749155

URL: http://svn.apache.org/viewvc?rev=1749155&view=rev
Log:
PDFBOX-3280: revert 1741295 because it resulted in split creating huge files

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1749155&r1=1749154&r2=1749155&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Jun 19 11:53:46 2016
@@ -42,11 +42,11 @@ import org.apache.pdfbox.io.RandomAccess
 import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream;
 import org.apache.pdfbox.io.RandomAccessRead;
 import org.apache.pdfbox.io.ScratchFile;
-import org.apache.pdfbox.multipdf.PDFCloneUtility;
 import org.apache.pdfbox.pdfparser.PDFParser;
 import org.apache.pdfbox.pdfwriter.COSWriter;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.common.PDStream;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
 import org.apache.pdfbox.pdmodel.encryption.PDEncryption;
 import org.apache.pdfbox.pdmodel.encryption.ProtectionPolicy;
@@ -504,26 +504,34 @@ public class PDDocument implements Close
      * document and want to copy the contents to this document's scratch file then use this method otherwise just use
      * the {@link #addPage} method.
      * 
-     * Unlike {@link #addPage}, this method does a deep clone. This will be slower and have a larger
-     * memory footprint. However the deep clone is important to avoid resources getting lost if the
-     * source document is closed when the destination document is saved.
-     *
-     * If your page has annotations, and if these link to pages not in the target document, then the
-     * target document might become huge. What you need to do is to delete page references of such
-     * annotations. See
+     * Unlike {@link #addPage}, this method does a deep copy. If your page has annotations, and if
+     * these link to pages not in the target document, then the target document might become huge.
+     * What you need to do is to delete page references of such annotations. See
      * <a href="http://stackoverflow.com/a/35477351/535646">here</a> for how to do this.
      *
      * @param page The page to import.
      * @return The page that was imported.
-     *
+     * 
      * @throws IOException If there is an error copying the page.
      */
     public PDPage importPage(PDPage page) throws IOException
     {
-        PDFCloneUtility cloner = new PDFCloneUtility(this);
-        COSBase pageBase = cloner.cloneForNewDocument(page.getCOSObject());
-        PDPage importedPage = new PDPage((COSDictionary) pageBase, resourceCache);
-        addPage(importedPage);
+        PDPage importedPage = new PDPage(new COSDictionary(page.getCOSObject()), resourceCache);
+        InputStream in = null;
+        try
+        {
+            in = page.getContents();
+            if (in != null)
+            {
+                PDStream dest = new PDStream(this, in, COSName.FLATE_DECODE);
+                importedPage.setContents(dest);
+            }
+            addPage(importedPage);
+        }
+        catch (IOException e)
+        {
+            IOUtils.closeQuietly(in);
+        }
         return importedPage;
     }