A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/javaexamples/extract_image_from_pdf.htm below:

How to extract an image from a PDF using Java

How to extract an image from a PDF using Java Problem Description

How to extract an image from a PDF using java.

Solution

Following is the program to extract an image from a PDF using Java.

import java.awt.image.BufferedImage; 
import java.io.File; 

import javax.imageio.ImageIO; 
import org.apache.pdfbox.pdmodel.PDDocument; 
import org.apache.pdfbox.rendering.PDFRenderer;  

public class ExtractImageFromPdf {  
   public static void main(String args[]) throws Exception {  
      
      //Loading an existing PDF document 
      File file = new File("C:/pdfBox/ExtractImage_IP.pdf"); 
      PDDocument document = PDDocument.load(file); 
      
      //Instantiating the PDFRenderer class 
      PDFRenderer renderer = new PDFRenderer(document);  
      
      //Rendering an image from the PDF document 
      BufferedImage image = renderer.renderImage(0);  
      
      //Writing the image to a file 
      ImageIO.write(image, "JPEG", new File("C:/pdfBox/ExtractImage_OP.png")); 
      System.out.println("Image created"); 

      //Closing the document 
      document.close();  
   } 
}
Input Output

java_apache_pdf_box


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4