Aspose简介
Aspose是一个商业.NET类库,可以使得应用程序处理大量的文件任务。Aspose可以支持Doc,Docx,PDF,Excel 等格式的文件处理。我们可以通过使用Aspose生成、修改、转换和打印文档。
Aspose并非开源,所以在使用的时候需要获取版权,否则在操作文档中会显示版权相关信息的水印。
版权注册代码如下
/**
* @Description TODO
* @param licensePath 版权文件所在路径
* @Return void
* @Author Mr.Walloce
* @Date 2019/7/27 22:18
*/
private static void setLicense(String licensePath) {
try {
InputStream inputStream = FileCustUtil.class.getClassLoader().getResourceAsStream(licensePath);
License aposeLicense = new License();
aposeLicense.setLicense(inputStream);
} catch (Exception e) {
e.printStackTrace();
}
}
文档转换 -- word转PDF
/**
* @Description TODO
* @param inputPath 需要被转换的word全路径带文件名
* @param outPath 转换之后pdf的全路径带文件名
* @Return void
* @Author Mr.Walloce
* @Date 2019/7/27 13:47
*/
public static void docToPdf(String inputPath, String outPath) {
try {
//word文档
Document doc = new Document(inputPath);
//新建一个pdf文档
File file = new File(outPath);
FileOutputStream os = new FileOutputStream(file);
//保存为pdf文件,saveFormat取的是words包下的,值为:40
doc.save(os, com.aspose.words.SaveFormat.PDF);
os.close();
} catch (Exception e) {
e.printStackTrace();
}
}
** word文档转换为PDF文档时,是将word中的内容完全转换为PDF文档,包括word中的图片、表格等特殊的数据。 **
文档转换 -- exce