Link

Convert PDF to GIF

JPedal provides several methods to allow the conversion of a PDF file or directory of PDF files into GIF. Java examples use the GIFEncoderOptions classes.

Convert PDF to GIF from Command Line or another language

java -jar jpedal.jar --convert "inputFileOrDir" "outputDir" gif

Convert PDF to GIF in Java with convenience static method

ConvertPagesToImages.
writeAllPagesAsImagesToDir("inputFileOrDir", "outputDir" , "gif", 1.33f);

Convert PDF to GIF in Java with control over the image output

ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
if (convert.openPDFFile()) {
    try {    
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);            
            final File out = new File("/path/to/output/" + page + ".gif");
            //setters to control output 
            final GIFEncoderOptions options = new GIFEncoderOptions();
            JDeli.write(bi, options, out);
        }
    } catch (PdfException | IOException e) {
        e.printStackTrace();
    }
}
convert.closePDFfile();

Convert PDF to GIF in Java with control over the page range of the output

ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
// setPageRange gives you the ability to chose the pages you'd like using '-' or ':' for range 
// and ',' to move to the next range or you can simply put null for all the pages
convert.setPageRange(new PageRange("1-5,8:10,15")); 
// Above will give us pages 1 to 5(inclusive),8 to 10(inclusive) and 15
if (convert.openPDFFile()) {
    convert.getPageRange().forEachRemaining(page -> {
        try {
                final BufferedImage bi = convert.getPageAsImage(page);
                final File out = new File("/path/to/output/" + page + ".gif");
                JDeli.write(bi, options, out);  
                }} catch (PdfException | IOException e) {
                    e.printStackTrace();
            }                      
    });  
}
convert.closePDFfile();

Convert PDF to GIF thumbnails in Java with control over output image dimensions

ConvertPagesToImages.
writeAllPagesAsImagesToDir("inputFileOrDir", "outputDir" , "gif", new int[]{width,height});

or

ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
//fit with aspect ratio preserved (width will be 300 or height will be 400)
convert.setFitToSize(new int[]{300,400}); 
if (convert.openPDFFile()) {
    try {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".gif");
            JDeli.write(bi, OutputFormat.GIF, out);           
        }
    } catch (PdfException | IOException e) {
        e.printStackTrace();
    } 
}
convert.closePDFfile();

Convert PDF to GIF thumbnails in Java with control over scaling

ConvertPagesToImages convert = new ConvertPagesToImages("/path/to/file.pdf");
convert.setPageScaling(1.33f); //which gives same size as Acrobat at 100%
if (convert.openPDFFile()) {
    try {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".gif");
            JDeli.write(bi, OutputFormat.GIF, out);           
        }
    } catch (PdfException | IOException e) {
        e.printStackTrace();
    } 
}
convert.closePDFfile();

Convert PDF to GIF in Java with a password-protected PDF file

ConvertPagesToImages convert = new ConvertPagesToImages("/path/file.pdf");
convert.setPassword("password"); 
if (convert.openPDFFile()) {
    try {
        for (int page = 1; page <= convert.getPageCount(); page++) {
            final BufferedImage bi = convert.getPageAsImage(page);
            final File out = new File("/path/to/output/" + page + ".gif");
            JDeli.write(bi, OutputFormat.GIF, out); 
        }
    } catch (PdfException | IOException e) { 
        e.printStackTrace(); 
    } 
}
convert.closePDFfile();

If you are looking for upscaling or more complex control over the PDF to GIF conversion, ConvertPagesToHiResImages class has lots of additional options

Still need help? Send us your questions.