aspose-words去水印自用资源

官方文档https://docs.aspose.com/words/java/convert-a-document-to-pdf/

声明:限个人学习使用,商用后果与本人无关。

1.引入依赖
XML 复制代码
    <dependencies>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>18.6</version>
            <classifier>jdk16</classifier>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>aspose-maven-repository</id>
            <url>https://artifact.aspose.com/repo/</url>
        </repository>
    </repositories>
2.下载依赖后去依赖仓库位置删掉从官方源下载的版本

仓库路径/com/aspose/aspose-words/18.6

删除路径中aspose-words-18.6-jdk16.jar文件,使用我的资源文件替换

3.添加license.xml文件到src/main/resources目录下
XML 复制代码
<License>
  <Data>
    <Products>
      <Product>Aspose.Total for Java</Product>
      <Product>Aspose.Words for Java</Product>
    </Products>
    <EditionType>Enterprise</EditionType>
    <SubscriptionExpiry>20991231</SubscriptionExpiry>
    <LicenseExpiry>20991231</LicenseExpiry>
    <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>
  </Data>
  <Signature>
    sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
  </Signature>
</License>
4.添加工具类代码
java 复制代码
@Slf4j
public class MatchLicense {

    public static void init() {
        try {
            log.info("实现aspose-words授权 -> 去掉头部水印");
            /*
              实现匹配文件授权 -> 去掉头部水印 `Evaluation Only. Created with Aspose.Words. Copyright 2003-2018 Aspose Pty Ltd.` |
                                          `Evaluation Only. Created with Aspose.Cells for Java. Copyright 2003 - 2020 Aspose Pty Ltd.`
             */
            InputStream is = new ClassPathResource("license.xml").getInputStream();
            License license = new License();
            license.setLicense(is);
        } catch (Exception e) {
            log.error("《aspose-words授权》 失败: {}", e.getMessage());
        }
    }
}
5.使用示例:在使用api前调用方法即可
java 复制代码
        // 将Word文档转换为PDF
        ByteArrayInputStream wordInputStream = new ByteArrayInputStream(wordOutputStream.toByteArray());
        // 获得授权
        MatchLicense.init();
        Document doc = new Document(wordInputStream);
        doc.save(getOutputPath(), SaveFormat.PDF);
相关推荐
碳酸的唐1 小时前
A* 工程实践全指南:从启发式设计到可视化与性能优化
python·神经网络
.格子衫.2 小时前
Spring Boot 原理篇
java·spring boot·后端
多云几多2 小时前
Yudao单体项目 springboot Admin安全验证开启
java·spring boot·spring·springbootadmin
2301_768350234 小时前
Vue第二期:组件及组件化和组件的生命周期
前端·javascript·vue.js
Jabes.yang4 小时前
Java求职面试实战:从Spring Boot到微服务架构的技术探讨
java·数据库·spring boot·微服务·面试·消息队列·互联网大厂
聪明的笨猪猪4 小时前
Java Redis “高可用 — 主从复制”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
兮动人4 小时前
Spring Bean耗时分析工具
java·后端·spring·bean耗时分析工具
倔强青铜三4 小时前
苦练Python第64天:从零掌握多线程,threading模块全面指南
人工智能·python·面试
MESSIR224 小时前
Spring IOC(控制反转)中常用注解
java·spring