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

How to Convert PDF to JPEG in Java?

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

Getting JPG 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 jpg/jpeg 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 JPG APIs

In order to provide perfect PDF to JPEG conversion, there are some extra properties and methods.

//open PDF document from the local PDF file
public void loadPDF(String fileName);
//load PDF document from PDF stream
public void loadPDF(InputStream stream);
//you can get the total PDF page count before your conversion  
public int getPageCount();
//set resolution of output jpg image to improve the image quality
public void setDPI(int dpi);

Depending to your needs, you can render jpeg image from PDF pages with original size, or you can render jpg image from PDF pages with specify size(such as you want to get thumbnail image from each PDF pages).

//convert PDF to jpg/jpeg image with default page size
public BufferedImage toImage(int pageIndex);
//convert PDF to jpg image with target customized size
public BufferedImage toImage(int pageIndex, int width, int height);

Turning PDF Pages to JPG in Java class

Here is a simple example to show you how to transform PDF to jpg/jpeg image in Java code. You can see in this example, only two steps can lead you getting the jpg image from PDF.

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

public class PDFtoJPGConverter {

   public static void main(String[] args)
   {
       try
       {
           //first, load PDF document to memory
           PDFDocument doc = new PDFDocument();           
           doc.loadPDF("Sample.pdf");
           
           int pageCount = doc.getPageCount();

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

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

convert pdf page to jpg image in java

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