java word 转pdf
时间: 2023-11-19 12:04:48 浏览: 208
java word转pdf
5星 · 资源好评率100%
以下是两种Java Word转PDF的方法:
1. 使用Jacob库进行转换
```java
public static void main(String[] args) {
String docPath = "C:\\Users\\Administrator\\Desktop\\test.docx";
String pdfPath = "C:\\Users\\Administrator\\Desktop\\test.pdf";
boolean res = Word2PdfJacobUtil.word2PDF(docPath, pdfPath);
System.out.println(res);
}
```
2. 使用Apache POI和iText库进行转换
```java
public static void main(String[] args) throws Exception {
FileInputStream fileInputStream = new FileInputStream("F:\\poi笔记.docx");
XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream);
PdfOptions pdfOptions = PdfOptions.create();
FileOutputStream fileOutputStream = new FileOutputStream("F:\\poi笔记.pdf");
PdfConverter.getInstance().convert(xwpfDocument,fileOutputStream,pdfOptions);
fileInputStream.close();
fileOutputStream.close();
}
```
阅读全文