java word转 pdf
<!-- https://mvnrepository.com/artifact/com.luhuiguo/aspose-words --> <dependency> <groupId>com.luhuiguo</groupId> <artifactId>aspose-words</artifactId> <version>22.4</version> <type>pom</type> </dependency>
代码如下:
package com.test.vn;
import com.aspose.words.Document;
import com.test.sdp.exception.support.BusinessException;
import java.io.File;
import java.io.FileOutputStream;
public class WordToPdf {
/**
● @param wordPath word路径
● @param pdfPath pdf输出路径
*/
public static void textWordToPdf(String wordPath, String pdfPath) {
FileOutputStream os = null;
try {
File file = new File(pdfPath);
os = new FileOutputStream(file);
Document doc = new Document(wordPath);
doc.save(os, com.aspose.words.SaveFormat.PDF);
} catch (Exception e) {
throw new BusinessException("worldToPdf失败");
} finally {
if (os != null) {
}
}
}
public static void main(String[] args) throws Exception {
String wordPath = "F:\\工作\\PDF字体样式要求.docx";
String pdfPath = "F:\\工作\\405nnn23.pdf";
textWordToPdf(wordPath, pdfPath);
}
}
效果图如下:



浙公网安备 33010602011771号