1.pom
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf-gae</artifactId>
<version>2.0.2</version>
<exclusions>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>poi-ooxml</groupId>
</exclusion>
</exclusions>
</dependency>
2.使用
public void peekReportPdf(HttpServletResponse response) {
try{
InputStream inputStream = new FileInputStream("F:\\word.docx");
XWPFDocument xwpfDocument = new XWPFDocument(inputStream);
PdfOptions pdfOptions = PdfOptions.create();
OutputStream outputStream = response.getOutputStream();
PdfConverter.getInstance().convert(xwpfDocument, outputStream, pdfOptions);
// Set the response headers
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
response.addHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(reprotName, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}
}
标签:java,xwpfDocument,poi,word,pdfOptions,pdf,response From: https://www.cnblogs.com/h-w-b/p/17352151.html