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

How to Convert PDF to GIF in Java?

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

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.

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 GIF APIs

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 properties:

//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);

Transforming PDF Pages to GIF in Java class

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();
       }
   }
}

convert pdf page to gif image in java

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