File lo = new File(lookupFileName);
String filePath = lo.getParent().concat("/outPDF.pdf");
BufferedImage image = null;
RenderedImage rendImage = null;
// open the url
Document document = new Document();
try {
document.setFile(filePath);
} catch (PDFException ex) {
System.out.println("Error parsing PDF document " + ex);
} catch (PDFSecurityException ex) {
System.out.println("Error encryption not supported " + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error file not found " + ex);
} catch (IOException ex) {
System.out.println("Error handling PDF document " + ex);
}
// Increasing the scale value for increases the quality of image produced but at cost of more execution time
float scale = 5.0f;
float rotation = 0f;
// Paint each pages content to an image and write the image to file
for (int i = 0; i < document.getNumberOfPages(); i++) {
image = (BufferedImage) document.getPageImage(i, GraphicsRenderingHints.SCREEN,
Page.BOUNDARY_CROPBOX, rotation, scale);
rendImage = image;
// capture the page image to file
try {
System.out.println("\t capturing page " + i);
File file = new File(out + ".png");
ImageIO.write(image, "png", file);
} catch (IOException e) {
e.printStackTrace();
}
image.flush();
}
// clean up resources
document.dispose();
return image;
}