pom依赖:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
<version>2.0.1</version>
</dependency>
测试代码:
@Test public void test() { FileInputStream fileInputStream = null; FileOutputStream fileOutputStream = null; try { fileInputStream = new FileInputStream("D:\\download\\xxx.docx"); XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream); PdfOptions pdfOptions = PdfOptions.create(); fileOutputStream = new FileOutputStream("D:\\download\\xxx.pdf"); PdfConverter.getInstance().convert(xwpfDocument,fileOutputStream,pdfOptions); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (null != fileInputStream) { fileInputStream.close(); } if (null != fileOutputStream) { fileOutputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } }