Aspose-Words文档处理类库-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

Aspose-Words文档处理类库

简介: Aspose-Words文档处理类库

简介

Aspose.Words for Java is a class library that enables your applications to perform a great range of document processing tasks. Aspose.Words supports DOC, DOCX, RTF, HTML, OpenDocument, PDF, XPS, EPUB and other formats. With Aspose.Words you can generate, modify, convert, render and print documents without using Microsoft Word®.

官网文档: https://docs.aspose.com/display/wordsjava/Home
官网代码示例: https://github.com/aspose-words/Aspose.Words-for-Java.git

同类别软件: Apache POI

注:

  1. Aspose需要商业授权,POI开源免费
  2. 对于简单的文档关键字替换使用POI
  3. 复杂的表格编辑,使用Aspose中的标签替换
  4. 对于替换参数(数字,文本,表格,图片等),可封装替换参数,增强代码的适用性

代码示例

Java类库

Maven

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>19.5</version>
    <classifier>jdk17</classifier>
</dependency>

直接引入Jar

aspose-words-19.5-jdk17.jar

简单示例

加载license

try {
    License license = new License();
    license.setLicense("Aspose.Words.lic");
    System.out.println("License set successfully.");
} catch (Exception e) {
    System.out.println("There was an error setting the license: " + e.getMessage());
}

Word->PDF

File file = new File("/Test-01.docx");

Document document = new Document(new FileInputStream(file));
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.getOutlineOptions().setHeadingsOutlineLevels(5);

OutputStream outputStream = new FileOutputStream("/Test-01.pdf");
document.save(outputStream,pdfSaveOptions);

书签文本替换

document.getRange().getBookmarks().get(bookMakeName).setText(word);

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: