Here is Java sample code to export PDF pages to images in various formats: PNG, JPG and TIFF using Qoppa’s PDF library jPDFImages.

When opening the PDF document, the sample below read the document from a local file, the code can be simply changed to read the file from a file input stream instead.

Export PDF to PNG

// open the PDF
PDFImages pdfDoc = new PDFImages ("C://test//mydoc.pdf", null);
// loop through the pages
for (int count = 1; count <= pdfDoc.getPageCount(); ++count)
{
// export page image at 150 DPI resolution in PNG format
 pdfDoc.savePageAsPNG(count-1, "C://test//image_page_" + count + ".png", 150);
// export page thumbnail at 20 DPI resolution in PNG format
 pdfDoc.savePageAsPNG(count-1, "C://test//thumbnail_page_" + count + ".png", 20);
}

Export PDF to JPEG

// open the PDF
PDFImages pdfDoc = new PDFImages ("C://test//mydoc.pdf", null);
// loop through the pages
for (int count = 1; count <= pdfDoc.getPageCount(); ++count)
{
// export page image at 150 DPI resolution in JPEG format
 pdfDoc.savePageAsJPEG(count-1, "C://test//image_page_" + count + ".jpg", 150, 0.8f);
// export page thumbnail at 20 DPI resolution in JPEG format
 pdfDoc.savePageAsJPEG(count-1, "C://test//thumbnail_page_" + count + ".jpg", 20, 0.8f);
}

Export PDF Pages to TIFF

// open the PDF
PDFImages pdfDoc = new PDFImages ("C://test//mydoc.pdf", null);
// loop through the pages
for (int count = 1; count <= pdfDoc.getPageCount(); ++count)
{
// export page image at 150 DPI resolution in TIFF format
 pdfDoc.savePageAsTIFF(count-1, "C://test//image_page_" + count + ".tiff", new TIFFOptions (150, TIFFOptions.TIFF_PACKBITS));
// export page thumbnail at 20 DPI resolution in TIFF format
 pdfDoc.savePageAsTIFF(count-1, "C://test//thumb_page_" + count + ".tiff", new TIFFOptions (20, TIFFOptions.TIFF_PACKBITS));
}

Export Whole PDF Document to Multi Page TIFF

It is possible to export all pages in the PDF document to a single TIFF:

PDFImages pdfDoc = new PDFImages ("C://test//mydoc.pdf", null);
pdfDoc.saveDocumentAsTIFF("C://test//mydoc.tif", new TIFFOptions (150, TIFFOptions.TIFF_PACKBITS));

Try It Now!

Try our sample / demo applications on your own PDF and see how robust jPDFImages PDF to Image Conversion is:

Download  Sample Application for jPDFImages