1.maven引用包
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
<version>2.0.2</version>
</dependency>
2.Java代码
public Boolean getDocxPdf(String inPath, String pdfName) throws IOException {
URL url = new URL(inPath);
URLConnection connection = url.openConnection();
InputStream fileInputStream = connection.getInputStream();
XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream);
PdfOptions pdfOptions = PdfOptions.create();
FileOutputStream fileOutputStream = new FileOutputStream(pdfName);
PdfConverter.getInstance().convert(xwpfDocument, fileOutputStream, pdfOptions);
fileInputStream.close();
fileOutputStream.close();
return true;
}
|