Java code gets the first page of the PDF file as a cover thumbnail

Source: Internet
Author: User

package gcjsxh.util;import java.awt.image.bufferedimage;import;import;import java.util.iterator;import javax.imageio.iioimage;import  Javax.imageio.imageio;import javax.imageio.imagewriter;import ;import org.icepdf.core.pobjects.document;import;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) ();                          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:

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

Java code gets the first page of the PDF file as a cover thumbnail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.