使用spire.pdf 非常简单。
查看 https://mvnrepository.com/artifact/e-iceblue/spire.pdf
注意,这个包在 e-iceblue 下。
下面开始撸代码
先来pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>pdfToWord</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>9.10.3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>com.e-iceblue</id>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
java代码。App.java
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import java.io.*;
public class App {
public static void main(String[] args) {
// 加载pdf文件
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("Django基础教程.pdf");
//保存为Excel文档
pdf.saveToFile("Django基础教程.docx", FileFormat.DOCX);
pdf.dispose();
}
}
注意: maven的setting.xml要配置
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*,!com.e-iceblue</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>