1、maven
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependency>
<groupId> e-iceblue </groupId>
<artifactId>spire.pdf</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf.free</artifactId>
<version>2.2.2</version>
</dependency>
2、代码
public static void main(String[] args) {
try {
PdfDocument doc = new PdfDocument();
doc.loadFromFile("C:\\Users\\EDZ\\Desktop\\测试.pdf");
StringBuilder sb = new StringBuilder();
PdfPageBase page;
for (int i = 0; i < doc.getPages().getCount(); i++) {
//获取每一行的page对象
page = doc.getPages().get(i);
sb.append(page.extractText(true));
//这个if中是图片的解析输出
if (page.extractImages() != null) {
for (BufferedImage image : page.extractImages()) {
if (image != null) {
//指定输出图片名,指定图片格式,后缀自己换
File output = new File("D:\\pdf\\img.png");
ImageIO.write(image, "PNG", output);
}
}
}
}
System.out.println(sb);
doc.close();
} catch (Exception e) {
e.printStackTrace();
}
}