File pdfFile = new File(pdfPath); String filepath = pdfPath.substring(0,pdfPath.lastIndexOf(".")); String pdfJpgPath = null; try { //加载pdf文件 PDDocument doc = Loader.loadPDF(pdfFile);; //读取pdf文件 PDFRenderer renderer = new PDFRenderer(doc); int pageCount = doc.getNumberOfPages(); BufferedImage image; for (int i = 0; i < pageCount; i++) { image = renderer.renderImageWithDPI(i, 105); pdfJpgPath = filepath+"_" + (i + 1) + "pdf.jpg"; //保存图片 ImageIO.write(image, "jpg", new File(pdfJpgPath)); } } catch (IOException e) { e.printStackTrace(); }
pdf转jpg
最新推荐文章于 2024-10-17 13:23:11 发布