java实现PDF转图片

点击:更多干货及开源收录

1:需要jar依赖:icepdf-core-6.2.0.jar

2:实现流程:
    ①加入jar包依赖
    ②获取pdf文件对象
    ③pdf转图片并保存

3:调用核心代码

String pdfPath = "D:" + File.separator +"testFile" + File.separator;
Document document = new Document();
try{
    document.setFile(pdfPath + "test.pdf");
    //缩放比例
    float scale = 2.5f;
    //旋转角度
    float rotation = 0f;
    for (int i = 0; i < document.getNumberOfPages(); i++) {
        BufferedImage image = (BufferedImage)
        document.getPageImage(i,GraphicsRenderingHints.SCREEN, org.icepdf.core.pobjects.Page.BOUNDARY_CROPBOX, rotation, scale);
        RenderedImage rendImage = image;
        try {
            File file = new File(pdfPath + i + ".png");
            ImageIO.write(rendImage, "png", file);
        }catch (Exception e){
            e.printStackTrace();
        }
        image.flush();
    }
    document.dispose();
}catch(Exception e){
}

4:完整资源点击下载

点击:更多干货及开源收录

猜你喜欢

转载自blog.csdn.net/a1214624851/article/details/83958669