pdfBox 将pdf文件转成图片
3个jar包分别是 pdfBox 、fontbox、commons-logging。
public static boolean pdfToImg(String pdfPath,String imgDir){
File file = new File(pdfPath);
PDDocument doc;
try {
doc = PDDocument.load(file);
PDFRenderer renderer = new PDFRenderer(doc);
int pageCount = doc.getNumberOfPages();
for(int i=0;i<pageCount;i++){
BufferedImage image = renderer.renderImageWithDPI(i, 96);
String path=imgDir+File.separator;
if(new File(path).exists()==false){
new File(path).mkdirs();
}
ImageIO.write(image, "PNG", new File(imgDir+File.separator+i+".png"));
}
} catch (InvalidPasswordException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}