pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1600699 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdmodel/PDPage.java rendering/PDFRenderer.java
Date Thu, 05 Jun 2014 17:03:49 GMT
Author: lehmi
Date: Thu Jun  5 17:03:49 2014
New Revision: 1600699

URL: http://svn.apache.org/r1600699
Log:
PDFBOX-2101: page resources are automatically cleared after converting a page to an image

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java?rev=1600699&r1=1600698&r2=1600699&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPage.java Thu Jun  5 17:03:49
2014
@@ -775,4 +775,18 @@ public class PDPage implements COSObject
     {
         return this.getCOSDictionary().hashCode();
     }
+    
+    /**
+     * Calling this will release all cached information.
+     * 
+     */
+    public void clear()
+    {
+        if (pageResources != null)
+        {
+            pageResources.clear();
+        }
+        mediaBox = null;
+        parent = null;
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java?rev=1600699&r1=1600698&r2=1600699&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PDFRenderer.java Thu Jun
 5 17:03:49 2014
@@ -37,13 +37,26 @@ public class PDFRenderer
     protected final PDDocument document;
     // TODO keep rendering state such as caches here
 
+    private boolean clearResourcesAutomatically;
+    
     /**
      * Creates a new PDFRenderer.
      * @param document the document to render
      */
     public PDFRenderer(PDDocument document)
     {
+        this(document, true);
+    }
+
+    /**
+     * Creates a new PDFRenderer.
+     * @param document the document to render
+     * @param clearResourcesAutomatically indicates that all resources will be cleared automatically
after rendering
+     */
+    public PDFRenderer(PDDocument document, boolean clearResourcesAutomatically)
+    {
         this.document = document;
+        this.clearResourcesAutomatically = clearResourcesAutomatically;
     }
 
     /**
@@ -213,5 +226,9 @@ public class PDFRenderer
         PageDrawer drawer = new PageDrawer(this);   // TODO: need to make it easy to use
a custom PageDrawer
         drawer.drawPage(graphics, page, cropBox);
         drawer.dispose();
+        if (clearResourcesAutomatically)
+        {
+            page.clear();
+        }
     }
 }



Mime
View raw message