PDF to PNG - pqScan.com
Java PDF to PNG Converting PDF Pages into PNG Image Files in Java Download Trial Purchase Now

How to Convert PDF to PNG in Java?

back to home  >  Java PDF to Image SDK  >  How to Convert PDF to Image in Java  >  Convert PDF to PNG

Getting PNG image from PDF pages is a key feature in pqScan Java PDF to Image SDK. Java PDF to Image converter library is completely developed in Java SDK 1.6, and customers can easily integrate the transforming PDF pages to png function in their Java application.

Install Java PDF to Image Converter to your Java application

  • Copy pqScan.PDFtoImage.jar to your Java project library folder.
  • Add pqScan.PDFtoImage.jar to your Java classpath.

Java PDF to PNG APIs

Before your conversion, we provide some useful properties and methods.

//open PDF document from the PDF file at the disk
public void loadPDF(String fileName);
//open PDF document from PDF stream
public void loadPDF(InputStream stream);
//return whole PDF page count, so you can have some idea of what was going on  
public int getPageCount();
//set resolution of output png image to improve the image quality
public void setDPI(int dpi);

You can get png images from PDF pages with the size you wanting or as original image size.

//turn PDF to png image with default page size
public BufferedImage toImage(int pageIndex);
//turn PDF to png image with customized size
public BufferedImage toImage(int pageIndex, int width, int height);

Transforming PDF Pages to PNG in Java class

Look at the following Java sample code, it shows how to converting PDF to png images in just several lines code. It's really simple to understand and easy to use, isn't it?

import com.pqscan.pdftoimage.PDFDocument;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public class PDFtoPNGConverter
{
   public static void main(String[] args)
   {
       try
       {
           //initialize PDFDocument object
           PDFDocument doc = new PDFDocument();
           //load PDF document
           doc.loadPDF("Sample.pdf");
           //get total PDF page count
           int pageCount = doc.getPageCount();

           for(int i = 0; i < pageCount; i++)
           {
               //convert each PDF page to BufferedImage object
               BufferedImage image = doc.toImage(i);
               //save image as png image file
               ImageIO.write(image,"png", new File("output"+ i +".png"));
           }

       }
       catch (Exception e)
       {
            e.printStackTrace();
       }
   }
}

convert pdf page to png image in java

PDF to Image Convert to JPEG in Java Convert to BMP in Java Convert to GIF in Java Convert to TIFF in Java Convert to Multi-TIFF in Java