package gcjsxh.util;import java.awt.image.bufferedimage;import java.io.file;import java.io.fileoutputstream;import java.util.iterator;import javax.imageio.iioimage;import Javax.imageio.imageio;import javax.imageio.imagewriter;import javax.imageio.stream.imageoutputstream ;import org.icepdf.core.pobjects.document;import org.icepdf.core.pobjects.page;import org.icepdf.core.util.graphicsrenderinghints;public class capturepdffirstpageutil { / ** * generate a book thumbnail * @param inputfile the full path of the book that needs to generate thumbnails * @ param outputfile the placement path of the generated thumbnail */ public static void generatebookiamge (String inputfile, string outputfile) { document document = null; try { float rotation = 0f; //thumbnail display multiples, 1 for no scaling, 0.5 for zoom out to 50% float zoom = 0.8f; document = new Document (); document.setfile (InputFile) ; // maxpages = Document.getpagetree (). Getnumberofpages (); bufferedimage image = (BufferedImage) Document.getpageimage (0, graphicsrenderinghints.screen, Page.boundary_cropbox, rotation, zoom); iterator iter = imageio.getimagewritersbysuffix ("JPG"); ImageWriter writer = (ImageWriter) iter.next (); Fileoutputstream out = new fileoutputstream (New file (outputFile)); &nBsp; imageoutputstream outimage = imageio.createimageoutputstream (out); writer.setoutput (outimage); writer.write (New iioimage (image, null, null)); } catch (exception e) { system.out.println ( "To generate thumbnail of a book fail : " + inputFile ); system.out.println ( e ); } } public static void main (String[] args) { cApturepdffirstpageutil.generatebookiamge ("C:\\users\\work\\desktop\\spring2.pdf", "C:\\Users\\work\\Desktop\\ Captureimage.jpg ") ; } }
Icepdf jar Package Address: http://down.51cto.com/data/2302789
Notice that when you introduce the jar package, don't get the wrong lead.
This article is from "Linux rookie" blog, please be sure to keep this source http://asura1992.blog.51cto.com/8159058/1919275
Java code gets the first page of the PDF file as a cover thumbnail