Java technology Development, convert PDF document to picture, use PDFRenderer-0.9.0 rack package

Source: Internet
Author: User

In fact, the use is not simple, will rack package import, but, I imported a rack package, some use of class method did not, have imported the base rack package Rt.jar

Method implementation:

Public ldc_pdftojpg (String Pdfpath, String jpgpath) throws IOException {

File File = new file (Pdfpath);
Randomaccessfile RAF = new Randomaccessfile (file, "R");
FileChannel channel = Raf.getchannel ();
Bytebuffer buf = Channel.map (FileChannel.MapMode.READ_ONLY, 0, Channel.size ());
Pdffile pdffile = new Pdffile (BUF);

for (int i = 1; I <= pdffile.getnumpages (); i++) {
Pdfpage page = Pdffile.getpage (i);
Rectangle rect = new Rectangle (0, 0, (int) Page.getbbox (). GetWidth (), (int) Page.getbbox (). GetHeight ());
Image img = page.getimage (rect.width, Rect.height, rect,//clip
Rect
NULL,//null for the ImageObserver
True,//fill background with white
True//block until drawing is done
);

BufferedImage tag = new BufferedImage (Rect.width, Rect.height, Bufferedimage.type_int_rgb);
Tag.getgraphics (). DrawImage (img, 0, 0, rect.width, rect.height, NULL);

Output to file stream
FileOutputStream out = new FileOutputStream (Jpgpath + i + ". jpeg");

JPEGImageEncoder encoder = Jpegcodec.createjpegencoder (out);
Encoder.encode (tag); JPEG encoding

Out.close ();
}

}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||

Write the pdf file path and picture path.

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||

Test

Fun = new Ldc_pdftojpg (

"c:\\users\\administrator\\desktop\\pdftojpg" + "\ \" + "Test.pdf",
"C:\\users\\administrator\\desktop\\pdftojpg\\"

);

Ok!

Java technology Development, convert PDF document to picture, use PDFRenderer-0.9.0 rack package

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: info-contact@alibabacloud.com 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.