pdf转图片
依赖
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
<version>2.0.24</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
代码
/**
* pdf转图片 目前只转第一页
*
* @param pdfPath pdf文件路径
* @param outPath 转为图片的输出路径
*/
public static void pdfToImg(String pdfPath, String outPath){
PDDocument doc = null;
try {
doc = PDDocument.load(new File(pdfPath));
PDFRenderer renderer = new PDFRenderer(doc);
// 0:转pdf第一页
BufferedImage image = renderer.renderImageWithDPI(0, 144);
ImageIO.write(image, "png", new File(outPath));
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (null != doc) {
doc.close();
}
} catch (Exception ignored) {}
}
}
标签:pdfPath,doc,outPath,new,pdf,图片,pdfbox
From: https://www.cnblogs.com/zjh0420/p/17286522.html