Here is a Java sample code showing how to export images of pages in a PDF document (in jpg, png or tiff format) using jPDFViewer. jPDFViewer is a Java Swing component that can display PDF documents and also allows to get page images from a PDF document as BufferedImage objects which can then be saved to image files using ImageIO.
// create the PDF Viewer Bean PDFViewerBean viewerBean = new PDFViewerBean(); // load a PDF document into the bean viewerBean.loadPDF("C:\\test\\mydoc.pdf"); // get the Document object IPDFDocument document = viewerBean.getDocument(); // loop through all the pages in the PDF document for(int count = 0; count < document.getPageCount(); count++) { // get the current page IPDFPage page = document.getIPage(count); // get width and height int width = (int) page.getDisplayWidth(); int height = (int) page.getDisplayHeight(); // get the image from the current page as a BUfferedImage object BufferedImage pageImage = page.getImage(width, height, false ); // save the image to a file (here in jpeg format) File outputfile = new File("C:\\test\\image_" + (count+1) + ".jpg"); ImageIO.write(pageImage, "jpg", outputfile); } |