How to Convert PDF to Image in Java

In this tutorial, we will cover how to convert PDF to Image in Java. We will start with a PDF file and convert it to the JPG format in this guide. This guide includes all the necessary steps and sample code to perform document conversion. Convert PDF to Image with Java is a simple process that just requires a few lines of code and requires no third-party software.

Steps to Convert PDF to Image in Java

  1. Setup GroupDocs.Conversion for Java from Maven repository in Java application
  2. Create an instance of the Converter class and pass the PDF file
  3. Create an object of the ImageConvertOptions class
  4. Call Convert method of the Converter class, specify the file name of the converted JPG file and instance of the ImageConvertOptions class

Here we have discussed the points that will be used to convert PDF to JPG in Java. It’s a very simple process to perform basic document transformation with a few lines of code by following these steps. However, you may implement several features for the converted image such as set color mode, set compression mode, adjust brightness, adjust contrast, flip image, and many more.

Code to Convert PDF to Image in Java

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.licensing.License;
import com.groupdocs.conversion.options.convert.ImageConvertOptions;
public class ConvertPdfToImageInJava {
public static void main(String[] args) { // Main function to convert PDF to Image in Java
// Remove the watermark in output Image document by adding license
License lic = new License();
lic.setLicense("GroupDocs.Conversion.lic");
// Load the source PDF file for conversion to Image
Converter converter = new Converter("sample.pdf");
// Set the convert options for JPG format
ImageConvertOptions options = new ImageConvertOptions();
// Convert and save the PDF in JPG format
converter.convert("converted.jpg", options);
System.out.println("Done");
}
}

This sample code demonstrates how to conduct a basic conversion using the Java convert PDF to Image feature. You may also use java code to convert pdf to image to convert other image formats such as PNG, GIF, TIFF, BMP, and many others. You can also convert any source document to the image formats specified above, as well as many more.

If you are interested to learn document conversion for PDF to Word in Java, visit our article on how to convert Pdf to Word in Java.

 English