In Ghost4J library (http://ghost4j.sourceforge.net), since version 0.4.0 you can use a SimpleRenderer to do the job with few lines of code:
Load PDF or PS file (use PSDocument class for that):
PDFDocument document = new PDFDocument();
document.load(new File("input.pdf"));
Create the renderer
SimpleRenderer renderer = new SimpleRenderer();
// set resolution (in DPI)
renderer.setResolution(300);
Render
List<Image> images = renderer.render(document);
Then you can do what you want with your image objects, for example, you can write them as PNG like this:
for (int i = 0; i < images.size(); i++) {
ImageIO.write((RenderedImage) images.get(i), "png", new File((i + 1) + ".png"));
}
Note: Ghost4J uses the native Ghostscript C API so you need to have a Ghostscript installed on your box.
I hope it will help you :)
Take a look at the articles:
1) PdftoImage-Convert PDF to Image by using PdfRenderer library, direct link to source code
2) Java: Generating PDF and Previewing it as an Image – iText and PDF Renderer
jPDFImages is not free but a commercial library which converts PDF pages to images in JPEG, TIFF or PNG format. The output image size is customizable.
If GPL is fine you may have an additional look at jPodRenderer (SourceForge)
Apache PDF Box can convert PDFs to jpg,bmp,wbmp,png, and gif.
The library even comes with a command line utility called PDFToImage to do this.
If you download the source code and look at the PDFToImage class you should be able to figure out how to use PDF Box to convert PDFs to images from your own Java code.
Source: Stackoverflow.com