- Copy pqScan.PDFtoImage.jar to your Java project library folder.
- Add pqScan.PDFtoImage.jar to your Java classpath.
How to Convert PDF to BMP in Java?
Getting BMP 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 bmp function in their Java application.
Support properties:
//before converting PDF to bmp, you can get all the PDF page count to decide which one to convert public int getPageCount(); //changing output bmp image quality and definition by setting image resolution public void setDPI(int dpi);
Support methods:
//load PDF document from the local file public void loadPDF(String fileName); //open PDF document from PDF stream public void loadPDF(InputStream stream); //get bmp image from current PDF page public BufferedImage toImage(int pageIndex); //get bmp image from current PDF page, you can set the output image size public BufferedImage toImage(int pageIndex, int width, int height);
As we provide flexible properties and methods, you can easy to use these to open a PDF document and convert it to bmp image format. Here the Java sample codes are listed to introduce you how to transform PDF to bmp images. And we also provide article for getting customized size of images from PDF pages in Java.
import com.pqscan.pdftoimage.PDFDocument; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; public class PDFtoBMPConverter { 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 image BufferedImage image = doc.toImage(i); //save image as bmp image file ImageIO.write(image,"bmp", new File("output"+ i +".bmp")); } } catch (Exception e) { e.printStackTrace(); } } }