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);
相关推荐
~-~%%6 小时前
Moe机制与pytorch实现
人工智能·pytorch·python
深耕AI7 小时前
【PyTorch训练】为什么要有 loss.backward() 和 optimizer.step()?
人工智能·pytorch·python
帧栈7 小时前
开发避坑指南(46):Java Stream 对List的BigDecimal字段进行求和
java
新手村领路人7 小时前
Firefox自定义备忘
前端·firefox
重生之我是Java开发战士7 小时前
【数据结构】Java集合框架:List与ArrayList
java·数据结构·list
乖女子@@@7 小时前
css3新增-网格Grid布局
前端·css·css3
爱干饭的boy7 小时前
手写Spring底层机制的实现【初始化IOC容器+依赖注入+BeanPostProcesson机制+AOP】
java·数据结构·后端·算法·spring
影子24017 小时前
java jdbc连接sqlserver2008R2版本数据库报错,驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接
java·数据库·ssl
0_0梅伊阁诗人7 小时前
Django ORM 模型
开发语言·数据库·笔记·python·oracle·django
失散137 小时前
分布式专题——10.1 ShardingSphere介绍
java·分布式·架构·shardingsphere·分库分表