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