public static void pdfImg(String inputPdf, long ItemId, String outPut){
//加载PDF文件
PdfDocument doc = new PdfDocument();
doc.loadFromFile(inputPdf);
//保存PDF的每一页到图片
BufferedImage image;
for (int i = 0; i < doc.getPages().getCount(); i++) {
image = doc.saveAsImage(i);
String path = outPut+ItemId+"_img_"+(i+1)+".png";
File file = new File( String.format(path, i));
try {
ImageIO.write(image, "PNG", file);
} catch (IOException e) {
e.printStackTrace();
}
}
doc.close();
}
public static void main(String ages[]) throws IOException {
String pdf = "C:\\Users\\zskx\\Desktop\\pdf\\123.pdf";
String dstImgFolder = "C:\\Users\\zskx\\Desktop\\pdf\\";
pdfImg(pdf,123L,dstImgFolder);
}
加群:687942640