1.在pom.xml中引入jar包;
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox --> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.24</version> </dependency>
2.实现下面的方法;
public static void main(String[] args) { try { String pdfFile = "C:\\Users\\zengh\\Desktop\\简历.pdf"; PDDocument doc = PDDocument.load(new File(pdfFile)); int pagenumber = doc.getNumberOfPages(); pdfFile = pdfFile.substring(0, pdfFile.lastIndexOf(".")); String fileName = pdfFile + ".doc"; File file = new File(fileName); if (!file.exists()) { file.createNewFile(); } FileOutputStream fos = new FileOutputStream(fileName); Writer writer = new OutputStreamWriter(fos, "UTF-8"); PDF