word转成pdf java
时间: 2023-12-06 16:36:20 浏览: 100
java word转换成pdf
以下是两种Java实现Word转PDF的方法:
1. 使用Jacob库实现Word转PDF
```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库实现Word转PDF
```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();
}
```
阅读全文