java中如何将一个word转PDF呢?

书欣 Java经验 发布时间:2022-10-19 22:45:44 阅读数:14045 1
下文笔者讲述Java中word转PDF文件的方法分享,如下所示
实现思路:
    借助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();
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaJingYan/202210/16661907874676.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者