pdfbox-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ravi Hegde (JIRA)" <j...@apache.org>
Subject [jira] [Created] (PDFBOX-1444) Capability to use custom PageDrawer in PDPage.convertToImage
Date Sat, 10 Nov 2012 04:49:12 GMT
Ravi Hegde created PDFBOX-1444:
----------------------------------

             Summary: Capability to use custom PageDrawer in PDPage.convertToImage
                 Key: PDFBOX-1444
                 URL: https://issues.apache.org/jira/browse/PDFBOX-1444
             Project: PDFBox
          Issue Type: Improvement
          Components: PDModel
    Affects Versions: 1.8.0
         Environment: Ubuntu 11.10 64 bit on Intel® Core™ i5-2430M CPU. Sun JDK "1.6.0_30"
(build 1.6.0_30-b12) Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode).
            Reporter: Ravi Hegde


Extending PageDrawer is a handy technique for PDF processing tools to get information about
the  elements drawn on the page while drawing the page in one go. However, PDPage.convertToImage
has no way of plugging in the extended PageDrawer class. It is necessary to provide some way
to use custom PageDrawer instance in PDPage.convertToImage. Overloaded PDPage.convertToImage
with a PageDrawer instance may be a good option. Here is the patch:

svn diff PDPage.java
Index: PDPage.java
===================================================================
--- PDPage.java	(revision 1407714)
+++ PDPage.java	(working copy)
@@ -699,6 +699,24 @@
      */
     public BufferedImage convertToImage(int imageType, int resolution) throws IOException
     {
+        PageDrawer drawer = new PageDrawer();
+        return convertToImage(imageType, resolution, drawer);
+    }
+
+    /**
+     * Convert this page to an output image using custom PageDrawer instance. 
+     * Custom page drawer is useful for collecting information about the 
+     * elements drawn on the page while drawing the page.
+     * 
+     * @param imageType the image type (see {@link BufferedImage}.TYPE_*)
+     * @param resolution the resolution in dpi (dots per inch)
+     * @param drawer Custom {@link PageDrawer} instance.
+     * @return A graphical representation of this page.
+     *
+     * @throws IOException If there is an error drawing to the image.
+     */
+    public BufferedImage convertToImage(int imageType, int resolution, PageDrawer drawer)
throws IOException
+    {
         PDRectangle cropBox = findCropBox();
         float widthPt = cropBox.getWidth();
         float heightPt = cropBox.getHeight();
@@ -753,7 +771,6 @@
             graphics.rotate((float)Math.toRadians(rotationAngle));
         }
         graphics.scale( scaling, scaling );
-        PageDrawer drawer = new PageDrawer();
         drawer.drawPage( graphics, this, pageDimension );
 
         return retval;


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message