Note: External files are required to download for performing the operation. For more documentation of the module used to refer to this.
Implementation:
// Extracting Images from a PDF using java import java.io.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.PDFRenderer; class GFG { public static void main(String[] args) throws Exception { // Existing PDF Document // to be Loaded using file io File newFile = new File("C:/Documents/GeeksforGeeks.pdf"); PDDocument pdfDocument = PDDocument.load(newFile); // PDFRenderer class to be Instantiated // i.e. creating it's object PDFRenderer pdfRenderer = new PDFRenderer(pdfDocument); // Rendering an image // from the PDF document // using BufferedImage class BufferedImage img = pdfRenderer.renderImage(0); // Writing the extracted // image to a new file ImageIO.write( img, "JPEG", new File("C:/Documents/GeeksforGeeks.png")); System.out.println( "Image has been extracted successfully"); // Closing the PDF document pdfDocument.close(); } }
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.