Word处理控件Aspose.Words功能演示:在 Java 中将 Word 文档转换为 EPUB

大多数智能设备,如智能手机、平板电脑、笔记本电脑等,都支持EPUB格式来查看或阅读文档。它是电子书或电子出版物的常用格式。另一方面,MS Word 格式,如DOCX、DOC等,是数字世界中广泛使用的文档格式之一。在本文中,我们将向您展示如何使用 Java 以编程方式将 MS Word 文件转换为 EPUB。此外,您将学习如何使用不同的选项自定义 Word 到 EPUB 的转换。

Aspose.Words for . words 最新下载(qun:761297826)icon-default.png?t=M85Bhttps://www.evget.com/product/564/download

用于 Word 到 EPUB 转换的 Java API

为了将 DOCX、DOC 等文件转换为 EPUB 格式,我们将使用Aspose.Words for Java。上述 API 允许您无缝地创建和操作 MS Word 文档。此外,您可以将 Word 文件高保真转换为其他格式,例如 EPUB、HTML、PDF 等。您可以下载API 的 JAR 文件或使用以下配置将其安装到基于 Maven 的应用程序中。

<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>21.11</version>
<type>pom</type>
</dependency>

在 Java 中将 Word 文档转换为 EPUB

以下是在 Java 中将 Word DOCX 文件转换为 EPUB 的步骤。

  • 使用Document类加载 Word 文件。
  • 使用Document.save(string)方法将文件转换为 EPUB 格式。

以下代码示例展示了如何在 Java 中将 DOCX 文件转换为 EPUB。

// Load the Word document
Document doc = new Document("document.docx");

// Convert Word document to EPUB
doc.save("word-to-epub.epub");

在 Java 中自定义 Word 到 EPUB 的转换

您还可以使用不同的选项修改 API 在 Word 到 EPUB 转换中的默认行为。例如,您可以指定编码方案、导出文档信息、设置拆分条件等。以下是自定义 Word 到 EPUB 转换的步骤。

  • 使用Document类加载 Word 文件。
  • 创建HtmlSaveOptions类的对象并设置所需的选项。
  • 使用Document.save(string, HtmlSaveOptions)方法将文件转换为 EPUB 。

以下代码示例显示了如何自定义 Word 到 EPUB 的转换。

// Load the Word document
Document doc = new Document("document.docx");

// Create an object for save options
HtmlSaveOptions saveOptions = new HtmlSaveOptions();

// Set the desired encoding
saveOptions.setEncoding(Charset.forName("UTF-8"));

// Specify at what elements to split the internal HTML at. This creates a new HTML within the EPUB
// which allows you to limit the size of each HTML part. This is useful for readers which cannot read
// HTML files greater than a certain size e.g 300kb.
saveOptions.setDocumentSplitCriteria(DocumentSplitCriteria.HEADING_PARAGRAPH);

// Enable export of document properties
saveOptions.setExportDocumentProperties(true);

// Specify save format
saveOptions.setSaveFormat(SaveFormat.EPUB);

// Convert Word document to EPUB
doc.save("word-to-epub.epub", saveOptions);

结论

在本文中,您学习了如何在 Java 中将 Word 文档转换为 EPUB 格式。此外,您还了解了如何使用不同的选项修改 Word 到 EPUB 的转换。此外,您还可以访问文档以了解 Aspose.Words for Java 提供的其他内容。此外,您可以通过在线客服联系我们!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值