pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1649141 - /pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java
Date Fri, 02 Jan 2015 22:20:59 GMT
Author: jahewson
Date: Fri Jan  2 22:20:59 2015
New Revision: 1649141

URL: http://svn.apache.org/r1649141
Log:
PDFBOX-2587: Add -time flag to PDFToImage

Modified:
    pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java

Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java?rev=1649141&r1=1649140&r2=1649141&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/PDFToImage.java Fri Jan  2 22:20:59
2015
@@ -50,6 +50,7 @@ public class PDFToImage
     private static final String RESOLUTION = "-resolution";
     private static final String DPI = "-dpi";
     private static final String CROPBOX = "-cropbox";
+    private static final String TIME = "-time";
 
     /**
      * private constructor.
@@ -83,6 +84,7 @@ public class PDFToImage
         float cropBoxLowerLeftY = 0;
         float cropBoxUpperRightX = 0;
         float cropBoxUpperRightY = 0;
+        boolean showTime = false;
         try
         {
             dpi = Toolkit.getDefaultToolkit().getScreenResolution();
@@ -161,6 +163,10 @@ public class PDFToImage
                 i++;
                 cropBoxUpperRightY = Float.valueOf(args[i]);
             }
+            else if( args[i].equals( TIME ) )
+            {
+                showTime = true;
+            }
             else
             {
                 if( pdfFile == null )
@@ -218,17 +224,29 @@ public class PDFToImage
                             cropBoxUpperRightX, cropBoxUpperRightY);
                 }
 
+                long startTime = System.nanoTime();
+
                 // render the pages
                 boolean success = true;
-                int numPages = document.getNumberOfPages();
+                endPage = Math.min(endPage, document.getNumberOfPages());
                 PDFRenderer renderer = new PDFRenderer(document);
-                for (int i = startPage - 1; i < endPage && i < numPages; i++)
+                for (int i = startPage - 1; i < endPage; i++)
                 {
                     BufferedImage image = renderer.renderImageWithDPI(i, dpi, imageType);
-                    String fileName = outputPrefix + (i + 1) + "." + imageFormat;       
            
+                    String fileName = outputPrefix + (i + 1) + "." + imageFormat;
                     success &= ImageIOUtil.writeImage(image, fileName, dpi);
                 }
 
+                // performance stats
+                long endTime = System.nanoTime();
+                long duration = endTime - startTime;
+                int count = 1 + endPage - startPage;
+                if (showTime)
+                {
+                    System.err.printf("Rendered %d page%s in %dms\n", count, count == 1 ?
"" : "s",
+                                      duration / 1000000);
+                }
+
                 if (!success)
                 {
                     System.err.println( "Error: no writer found for image format '"
@@ -261,6 +279,7 @@ public class PDFToImage
             "  -color <string>                The color depth (valid: bilevel, indexed,
gray, rgb, rgba)\n" +
             "  -dpi <number>                  The DPI of the output image\n" +
             "  -cropbox <number> <number> <number> <number> The page
area to export\n" +
+            "  -time                          Prints timing information to stdout\n" +
             "  <PDF file>                     The PDF document to use\n"
             );
         System.exit( 1 );



Mime
View raw message