• 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 的应用程序中。

    
    AsposeJavaAPI
    Aspose Java API
    https://repository.aspose.com/repo/
    
    
    com.aspose
    aspose-words
    21.11
    pom
    
    

    在 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 提供的其他内容。此外,您可以通过在线客服联系我们!

  • 相关阅读:
    软考高级系统架构设计师系列之:案例分析典型试题三
    C语言数据结构串【BF\KMP算法】
    Verilog开源项目——百兆以太网交换机(二)AES加解密模块设计
    leetcode 55. 跳跃游戏
    学生个人单页面网页作业 学生网页设计成品 静态HTML网页单页制作 dreamweaver网页设计与制作代码 web前端期末大作业
    Linux应用基础——串口应用编程
    Python学习基础笔记五——列表
    EtherNet/IP协议开发:奠基仪式
    Python xlwings打开excel表格进行最大化
    终于有人把操作系统、网络系统、线程进程、IO模型全部总结出来了
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/128128271