pom引入
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
代码
/**
* PDF文件转PNG图片
* @return
*/
public void pdf2Image(String pdfPath, String path) throws InterruptedException, IOException {
File file = new File(pdfPath);
try {
PDDocument doc = PDDocument.load(file);
int endPage = null == doc ? Integer.MAX_VALUE : doc.getNumberOfPages();
PDFTextStripper stripper = new PDFTextStripper();
stripper.setSortByPosition(true);
stripper.setStartPage(1);
stripper.setEndPage(endPage);
String content = stripper.getText(doc);
System.out.println("pdf 文件解析,内容为:" + content);
PDFRenderer rende