PDF to Image - pqScan.com
Java PDF to Customized Size Images Converting PDF to Specific Size Images in Java Download Trial Purchase Now

How to Customize the Size of Images Getting from PDF in Java?

back to home  >  Java PDF to Image SDK  >  How to Convert PDF to Image in Java  >  Convert PDF to Customized Size Images

As mentioned before, developers can get wanted image quality in two ways in Java. One is setting DPI, the other is setting the target size of output image In this article, we provide two examples, first is changing size with DPI, the second is changing size in setting image width and height.

User-defined Image Size(PDF to single page image) - Java sample

In Java PDF to Image Library, the DPI is set to 72 as default. In many cases, you want to set higher resolution to get more clearimage(jpg/jpeg, png, bmp, gif and single page tiff) from PDF document.What's more, you can also set the wanted image size directly, then each image getting from PDF is in the input size.

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

public class CustomizeImageSize {

   public static void main(String[] args)
   {
       try
       {
           //create an instance of PDFDocument object
           PDFDocument doc = new PDFDocument();
           //load PDF document
           doc.loadPDF("f:/Sample.pdf");
           int pageCount = doc.getPageCount();

           for(int i = 0; i < pageCount; i++)
           {
               //render image in target size
               BufferedImage image = doc.toImage(i,100,200);
               //save specific size image 
               ImageIO.write(image,"jpg", new File("output"+i+".jpg"));
           } 
       }
       catch (Exception e) {
               e.printStackTrace();
       }
   }
}

User-defined Image Size(PDF to multiple pages tiff image) - Java sample

We only provide changing DPI to specify the picture quality in PDF to multi-page tiff in Java application.

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

public class CustomizeImageSize {

   public static void main(String[] args)
   {
       try
       {
           //initialise PDFDocument object
           PDFDocument doc = new PDFDocument();
           //load PDF document
           doc.loadPDF("Sample.pdf");
           //render multi-page tiff from PDF in 96 resolution
           doc.setDPI(96);
           //save multiple pages tiff to the disk
           doc.toMultiPageTiff("output.tiff");
       }
       catch (Exception e) {
               e.printStackTrace();
       }
   }
}
PDF to Image Convert to JPEG in Java 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