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);
相关推荐
qfZYG几秒前
Trae 编辑器在 Python 环境缺少 Pylance,怎么解决
前端·vue.js·编辑器
java亮小白1997几秒前
Spring Cloud 快速通关之Sentinel
java·spring cloud·sentinel
atwednesday1 分钟前
大规模文档预览的架构设计与实现策略
java
bug爱好者1 分钟前
Vue3 基于Element Plus 的el-input,封装一个数字输入框组件
前端·javascript
Silence_xl9 分钟前
RACSignal实现原理
前端
柯南二号10 分钟前
【大前端】实现一个前端埋点SDK,并封装成NPM包
前端·arcgis·npm
dangkei10 分钟前
【Wrangler(Cloudflare 的官方 CLI)和 npm/npx 的区别一次讲清】
前端·jvm·npm
乔公子搬砖11 分钟前
小程序开发提效:npm支持、Vant Weapp组件库与API Promise化(八)
前端·javascript·微信小程序·js·promise·vagrant·事件绑定
Dioass25 分钟前
Java面向对象中你大概率会踩的五大隐形陷阱
java
辣椒http_出海辣椒29 分钟前
如何使用python 抓取Google搜索数据
python