pq scan
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.
Getting GIF 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 gif function in their Java application.
Support properties:
//get total PDF page information before your conversion public int getPageCount(); //change resolution of output gif image to improve the image quality public void setDPI(int dpi);
Support methods:
//load the local PDF document public void loadPDF(String fileName); //load PDF stream public void loadPDF(InputStream stream); //render gif image from PDF page with original size public BufferedImage toImage(int pageIndex); //render gif image from PDF page with specify size public BufferedImage toImage(int pageIndex, int width, int height);
Now, we will introduce you how to convert PDF to gif in java. In the java code below, you can find only several lines code can do it for you. If you want to define the output image size, please see another guide: changing output image size from PDF using Java.
import com.pqscan.pdftoimage.PDFDocument; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; public class PDFtoGIFConverter { public static void main(String[] args) { try { //create an instance of 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++) { //get image from each PDF page BufferedImage image = doc.toImage(i); //save image as gif image format ImageIO.write(image,"gif", new File("output"+ i +".gif")); } } catch (Exception e) { e.printStackTrace(); } } }
Copyright © pqScan 2010-2023. All Rights Reserved.