apose转PDF,去除水印操作

去除水印操作参考:https://www.cnblogs.com/rickiyang/p/11336268.html

aspose使用教程

  1. maven引入被破解的版本(不推荐,推荐使用第2种方式)
    第一种:jar包在项目目录下。先把jar拷贝到项目目录下,然后在maven中配置依赖,代码如下:
<dependency>
   <groupId>com.aspose</groupId>
    <artifactId>words</artifactId>
    <version>20.8</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/java/lib/aspose-words-20.8-jdk17.jar</systemPath>
</dependency>
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>cells</artifactId>
    <version>20.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/java/lib/aspose-cells-20.4.jar</systemPath>
</dependency>

第二种:jar包在maven仓库。在pom中引入依赖,然后把破解的jar包拷贝到仓库中去,配置仓库中需要的pom文件即可,代码如下:

<dependency>
     <groupId>com.aspose</groupId>
     <artifactId>cells</artifactId>
     <version>20.4</version>
 </dependency>
 <dependency>
     <groupId>com.aspose</groupId>
     <artifactId>words</artifactId>
     <version>20.8</version>
 </dependency>
  1. 引入转PDF的工具
/**
* @param wordPath 需要被转换的word全路径带文件名
 */
public static File wordToPDF(String wordPath) throws Exception {
    String fileNameSuffix = FileHelper.getFileNameAndSuffix(wordPath);
    File file = null;
    if (StringUtils.isNotBlank(wordPath) && StringUtils.isNotBlank(fileNameSuffix)){
        String PDFPath = wordPath.split(fileNameSuffix)[0];
        String fileName = FileHelper.getFileNameByName(fileNameSuffix);
        //long old = System.currentTimeMillis();
        file = new File(PDFPath + fileName + ".pdf");
        if(!file.exists()){
            FileOutputStream os = new FileOutputStream(file);
            //Address是将要被转化的word文档
            Document doc = new Document(wordPath);
            //全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
            doc.save(os, com.aspose.words.SaveFormat.PDF);
            os.close();
            //long now = System.currentTimeMillis();
            //System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
            // 返回转化后的PDF文件
        }
    }
    return file;
}

/**
 * @param excelPath 需要被转换的excel全路径带文件名
 */
public static File excelToPDF(String excelPath) throws Exception {
    String fileNameSuffix = FileHelper.getFileNameAndSuffix(excelPath);
    File file = null;
    if (StringUtils.isNotBlank(excelPath) && StringUtils.isNotBlank(fileNameSuffix)) {
        String PDFPath = excelPath.split(fileNameSuffix)[0];
        String fileName = FileHelper.getFileNameByName(fileNameSuffix);
        long old = System.currentTimeMillis();
        file = new File(PDFPath + fileName + ".pdf");
        if(!file.exists()) {
            Workbook wb = new Workbook(excelPath);
            FileOutputStream fileOS = new FileOutputStream(file);
            wb.save(fileOS, com.aspose.cells.SaveFormat.PDF);
            fileOS.close();
            long now = System.currentTimeMillis();
            System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
            // 返回转化后的PDF文件
        }
    }
    return file;
}

/**
 * @param pptPath 需要被转换的ppt全路径带文件名
 */
public static File pptToPDF(String pptPath) throws Exception {
    String fileNameSuffix = FileHelper.getFileNameAndSuffix(pptPath);
    File file = null;
    if (StringUtils.isNotBlank(pptPath) && StringUtils.isNotBlank(fileNameSuffix)) {
        String PDFPath = pptPath.split(fileNameSuffix)[0];
        String fileName = FileHelper.getFileNameByName(fileNameSuffix);
        long old = System.currentTimeMillis();
        Workbook wb = new Workbook(pptPath);
        file = new File(PDFPath + fileName + ".pdf");
        FileOutputStream fileOS = new FileOutputStream(file);
        wb.save(fileOS, com.aspose.cells.SaveFormat.PDF);
        fileOS.close();
        long now = System.currentTimeMillis();
        System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒"); //转化用时
        // 返回转化后的PDF文件
    }
    return file;
}
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值