其他分享
首页 > 其他分享> > pdf转png图片

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();
        }
    }

  

标签:2.0,20,int,doc,file,pdf,图片,png,pdfbox
来源: https://www.cnblogs.com/yibuyi-123/p/14098011.html