Please choose a menu option
Visit the IDRsolutions WebSite

PDF to image conversion in Java

Here is a java code sample to provide PDF to image conversion in Java - just cut and paste into your code


/**instance of PdfDecoder to convert PDF into image*/
PdfDecoder decode_pdf = new PdfDecoder(true);

/**set mappings for non-embedded fonts to use*/
FontMappings.setFontReplacements();

/**open the PDF file - can also be a URL or a byte array*/
try {
    	decode_pdf.openPdfFile("C:/myPDF.pdf"); //file
		//decode_pdf.openPdfFile("C:/myPDF.pdf", "password"); //encrypted file
		//decode_pdf.openPdfArray(bytes); //bytes is byte[] array with PDF
		//decode_pdf.openPdfFileFromURL("http://www.mysite.com/myPDF.pdf",false);
		
    	/**get page 1 as an image*/
    	//page range if you want to extract all pages with a loop
    	//int start = 1,  end = decode_pdf.getPageCount();
    	BufferedImage img=decode_pdf.getPageAsImage(1);
	
	/**close the pdf file*/
	decode_pdf.closePdfFile();

} catch (PdfException e) {
    e.printStackTrace();
}

More complex PDF to Image conversion examples

ExtractPagesAsThumbnails - fully automated program to rasterize PDF pages as images and optionally scale.

HiResThumbnailExtraction - extract PDF pages at the best possible quality. If the images are larger than the PDF page, it scales up the PDF page rather than scaling down the image.

 

Return to main PDF support section

Click here for the main PDF support area with lots of java examples, PDF tutorials and useful information to get the most out of the JPedal PDF library

 


PDF viewer