java中如何将一个word转PDF呢?
下文笔者讲述Java中word转PDF文件的方法分享,如下所示
引入POI依赖
实现思路: 借助POI类即可实现word转PDF的操作例:
引入POI依赖
<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>编写相应的代码即可
FileInputStream fileInputStream = new FileInputStream("D:\\test.docx"); XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream); PdfOptions pdfOptions = PdfOptions.create(); FileOutputStream fileOutputStream = new FileOutputStream("D:\\test.pdf"); PdfConverter.getInstance().convert(xwpfDocument,fileOutputStream,pdfOptions); fileInputStream.close(); fileOutputStream.close();
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。