/**
* word文档转PDF
* @param docFilePath word文件路径
* @param pdfStringPath PDF文件路径
*
* 官方文档链接 <a href="https://reference.aspose.com/words/zh/java/com.aspose.words">...</a>
*/
private void wordToPdf(String docFilePath, String pdfStringPath){
FileOutputStream os = null;
try {
File file = new File(pdfStringPath);
os = new FileOutputStream(file);
Document document = new Document(docFilePath);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
//设置pdf的导航栏书签
OutlineOptions outlineOptions = pdfSaveOptions.getOutlineOptions();
/*
指定要包含在文档大纲中的标题级别(使用标题样式格式化的段落)
指定0表示大纲中没有标题;为
大纲中的一级标题指定 1,依此类推。默认值为 0。有效范围为 0 到 9。
*/
outlineOptions.setHeadingsOutlineLevels(3);
//指定转换的文档格式
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);
document.save(os ,pdfSaveOptions);
}catch (Exception e){
e.printStackTrace();
}finally {
if (os != null){
try {
os.flush();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
wordToPdf,word转PDF
最新推荐文章于 2024-05-14 23:13:17 发布