You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2013/05/07 21:17:55 UTC
svn commit: r1480030 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java
Author: lehmi
Date: Tue May 7 19:17:55 2013
New Revision: 1480030
URL: http://svn.apache.org/r1480030
Log:
PDFBOX-1293: use logger instead of system.out as proposed by Erik Froese
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java?rev=1480030&r1=1480029&r2=1480030&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFImageWriter.java Tue May 7 19:17:55 2013
@@ -23,18 +23,14 @@ import java.io.IOException;
import java.util.List;
import java.util.Properties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
-
/**
- * This class will take a PDF document and strip out all of the text and ignore the
- * formatting and such. Please note; it is up to clients of this class to verify that
- * a specific user has the correct permissions to extract text from the
- * PDF document.
- * <p>
- * Patterned after PDFTextStripper.
- *
+ * This class writes single pages of a pdf to a file.
+ *
* @author <a href="mailto:DanielWilson@Users.SourceForge.net">Daniel Wilson</a>
* @version $Revision: 1.1 $
*/
@@ -42,6 +38,11 @@ public class PDFImageWriter extends PDFS
{
/**
+ * Log instance.
+ */
+ private static final Log LOG = LogFactory.getLog(PDFImageWriter.class);
+
+ /**
* Instantiate a new PDFImageWriter object.
*/
public PDFImageWriter()
@@ -49,72 +50,89 @@ public class PDFImageWriter extends PDFS
}
/**
- * Instantiate a new PDFImageWriter object. Loading all of the operator mappings
- * from the properties object that is passed in.
- *
- * @param props The properties containing the mapping of operators to PDFOperator
- * classes.
- *
- * @throws IOException If there is an error reading the properties.
+ * Instantiate a new PDFImageWriter object. Loading all of the operator mappings from the properties object that is
+ * passed in.
+ *
+ * @param props
+ * The properties containing the mapping of operators to PDFOperator classes.
+ *
+ * @throws IOException
+ * If there is an error reading the properties.
*/
- public PDFImageWriter( Properties props ) throws IOException
+ public PDFImageWriter(Properties props) throws IOException
{
- super( props );
+ super(props);
}
/**
* Converts a given page range of a PDF document to bitmap images.
- * @param document the PDF document
- * @param imageType the target format (ex. "png")
- * @param password the password (needed if the PDF is encrypted)
- * @param startPage the start page (1 is the first page)
- * @param endPage the end page (set to Integer.MAX_VALUE for all pages)
- * @param outputPrefix used to construct the filename for the individual images
+ *
+ * @param document
+ * the PDF document
+ * @param imageType
+ * the target format (ex. "png")
+ * @param password
+ * the password (needed if the PDF is encrypted)
+ * @param startPage
+ * the start page (1 is the first page)
+ * @param endPage
+ * the end page (set to Integer.MAX_VALUE for all pages)
+ * @param outputPrefix
+ * used to construct the filename for the individual images
* @return true if the images were produced, false if there was an error
- * @throws IOException if an I/O error occurs
+ * @throws IOException
+ * if an I/O error occurs
*/
- public boolean writeImage(PDDocument document, String imageType, String password,
- int startPage, int endPage, String outputPrefix)
- throws IOException
+ public boolean writeImage(PDDocument document, String imageType, String password, int startPage, int endPage,
+ String outputPrefix) throws IOException
{
int resolution;
try
{
resolution = Toolkit.getDefaultToolkit().getScreenResolution();
}
- catch( HeadlessException e )
+ catch (HeadlessException e)
{
resolution = 96;
}
- return writeImage(document, imageType, password, startPage, endPage, outputPrefix,
- 8, resolution);
+ return writeImage(document, imageType, password, startPage, endPage, outputPrefix, 8, resolution);
}
/**
* Converts a given page range of a PDF document to bitmap images.
- * @param document the PDF document
- * @param imageFormat the target format (ex. "png")
- * @param password the password (needed if the PDF is encrypted)
- * @param startPage the start page (1 is the first page)
- * @param endPage the end page (set to Integer.MAX_VALUE for all pages)
- * @param outputPrefix used to construct the filename for the individual images
- * @param imageType the image type (see {@link BufferedImage}.TYPE_*)
- * @param resolution the resolution in dpi (dots per inch)
+ *
+ * @param document
+ * the PDF document
+ * @param imageFormat
+ * the target format (ex. "png")
+ * @param password
+ * the password (needed if the PDF is encrypted)
+ * @param startPage
+ * the start page (1 is the first page)
+ * @param endPage
+ * the end page (set to Integer.MAX_VALUE for all pages)
+ * @param outputPrefix
+ * used to construct the filename for the individual images
+ * @param imageType
+ * the image type (see {@link BufferedImage}.TYPE_*)
+ * @param resolution
+ * the resolution in dpi (dots per inch)
* @return true if the images were produced, false if there was an error
- * @throws IOException if an I/O error occurs
+ * @throws IOException
+ * if an I/O error occurs
*/
- public boolean writeImage(PDDocument document, String imageFormat, String password,
- int startPage, int endPage, String outputPrefix, int imageType, int resolution)
- throws IOException
+ public boolean writeImage(PDDocument document, String imageFormat, String password, int startPage, int endPage,
+ String outputPrefix, int imageType, int resolution) throws IOException
{
boolean bSuccess = true;
- List pages = document.getDocumentCatalog().getAllPages();
- for( int i = startPage - 1; i < endPage && i < pages.size(); i++ )
+ List<PDPage> pages = document.getDocumentCatalog().getAllPages();
+ int pagesSize = pages.size();
+ for (int i = startPage - 1; i < endPage && i < pagesSize; i++)
{
- PDPage page = (PDPage)pages.get( i );
+ PDPage page = pages.get(i);
BufferedImage image = page.convertToImage(imageType, resolution);
String fileName = outputPrefix + (i + 1);
- System.out.println( "Writing: " + fileName + "." +imageFormat);
+ LOG.info("Writing: " + fileName + "." + imageFormat);
bSuccess &= ImageIOUtil.writeImage(image, imageFormat, fileName, imageType, resolution);
}
return bSuccess;