}
List pages = document.getDocumentCatalog().getAllPages();
for( int i=startPage-1; i<endPage && i<pages.size(); i++ )
{
ImageOutputStream output = null;
ImageWriter imageWriter = null;
try
{
PDPage page = (PDPage)pages.get( i );
BufferedImage image = page.convertToImage();
String fileName = outputPrefix + (i+1) + "." + imageType;
System.out.println( "Writing:" + fileName );
output = ImageIO.createImageOutputStream( new File( fileName ) );
boolean foundWriter = false;
Iterator writerIter = ImageIO.getImageWritersByFormatName( imageType );
while( writerIter.hasNext() && !foundWriter )
{
try
{
imageWriter = (ImageWriter)writerIter.next();
ImageWriteParam writerParams = imageWriter.getDefaultWriteParam();
if(writerParams.canWriteCompressed() )
{
writerParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
writerParams.setCompressionQuality(1.0f);
}
imageWriter.setOutput( output );
imageWriter.write( null, new IIOImage( image, null, null), writerParams );
foundWriter = true;
}
catch( IIOException io )
{
//ignore exception
}
finally
{
if( imageWriter != null )
{
imageWriter.dispose();
}
}
}
if( !foundWriter )
{