官方文档https://docs.aspose.com/words/java/convert-a-document-to-pdf/
声明:限个人学习使用,商用后果与本人无关。
- <dependencies>
- <dependency>
- <groupId>com.asposegroupId>
- <artifactId>aspose-wordsartifactId>
- <version>18.6version>
- <classifier>jdk16classifier>
- dependency>
- dependencies>
- <repositories>
- <repository>
- <id>aspose-maven-repositoryid>
- <url>https://artifact.aspose.com/repo/url>
- repository>
- repositories>
仓库路径/com/aspose/aspose-words/18.6
删除路径中aspose-words-18.6-jdk16.jar文件,使用我的资源文件替换
- <License>
- <Data>
- <Products>
- <Product>Aspose.Total for JavaProduct>
- <Product>Aspose.Words for JavaProduct>
- Products>
- <EditionType>EnterpriseEditionType>
- <SubscriptionExpiry>20991231SubscriptionExpiry>
- <LicenseExpiry>20991231LicenseExpiry>
- <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7SerialNumber>
- Data>
- <Signature>
- sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=
- Signature>
- License>
- @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());
- }
- }
- }
- // 将Word文档转换为PDF
- ByteArrayInputStream wordInputStream = new ByteArrayInputStream(wordOutputStream.toByteArray());
- // 获得授权
- MatchLicense.init();
- Document doc = new Document(wordInputStream);
- doc.save(getOutputPath(), SaveFormat.PDF);