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

在 Java 中将 Word 文档转换为 EPUB

用于 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 documentDocument doc = new Document("document.docx");// Convert Word document to EPUBdoc.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 documentDocument doc = new Document("document.docx");// Create an object for save optionsHtmlSaveOptions saveOptions = new HtmlSaveOptions();// Set the desired encodingsaveOptions.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 propertiessaveOptions.setExportDocumentProperties(true);// Specify save formatsaveOptions.setSaveFormat(SaveFormat.EPUB);// Convert Word document to EPUBdoc.save("word-to-epub.epub", saveOptions);
结论

欢迎下载|体验更多Aspose产品

获取更多信息请咨询在线客服 或 加入Aspose技术交流群(
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年6月3日
下一篇 2022年6月3日

相关推荐

发表回复

登录后才能评论