pdf转png图片
maven依赖
<dependencies> <!--pdf转图片相关--> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.20</version> </dependency> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>fontbox</artifactId> <version>2.0.20</version> </dependency> </dependencies>
Java代码:
private static void pdf2image1() { File file = new File("C:/Users/v/Desktop/doc/测试.html.pdf"); try { PDDocument 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, 296); // BufferedImage image = renderer.renderImage(i, 2.5f); ImageIO.write(image, "PNG", new File("C:/Users/v/Desktop/doc/pdfbox_image"+i+".png")); } } catch (IOException e) { e.printStackTrace(); } }