使用 C# 将 Word DOC 转换为 EPUB
本指南介绍如何使用 C#将 Word DOC 转换为 EPUB。涵盖开发环境设置的详细信息、步骤列表以及使用 C开发 Word 文档转 EPUB 转换器的示例代码。此外,还分享如何通过设置 API 公开的各种属性来自定义输出 EPUB 文件。
使用 C将 DOCX 转换为 EPUB 的步骤包括:设置环境以使用 Aspose.Words for .NET 创建电子书;将源 Word 文件加载到 Document 对象中以转换为 EPUB;创建 HtmlSaveOptions 类的对象以自定义输出;设置 EPUB 属性;使用上述选项保存输出的 EPUB 文件。以下步骤详细讲解了使用 C将文件格式从 DOC 更改为 EPUB 的过程。加载源 Word 文件,创建 HtmlSaveOptions 类的实例,并设置所需的属性,例如 SaveFormat、导出文档属性的标志以及文档拆分条件。然后,使用 HtmlSaveOptions 对象将输出的 EPUB 文件保存到磁盘上。
使用 C将 DOC 转换为 EPUB 的代码示例如下:using Aspose.Words; using Aspose.Words.Saving; class Program { static void Main(string[] args) { License lic = new License(); lic.SetLicense("license.lic"); Document doc = new Document("SampleFile.docx"); HtmlSaveOptions options = new HtmlSaveOptions { DocumentSplitCriteria = DocumentSplitCriteria.HeadingParagraph, SaveFormat = SaveFormat.Epub, ExportDocumentProperties = true }; doc.Save("EPUB/OutputEbook.epub", options); System.Console.WriteLine("DOCX to EPUB converted successfully"); } }此代码演示了如何使用 C将 DOCX 文件转换为 EPUB 文件。HtmlSaveOptions 类包含各种属性,例如用于规范负缩进的 AllowNegativeIndent、分页符、分栏符或分节符等拆分条件、编码以及导出列表标签。DocumentSplitCriteria 会根据 HeadingParagraph 等条件生成多个文件,每个段落都会渲染为单独的 EPUB 文件。
本文教我们如何从 DOC 转换为 EPUB。要将 HTML 文件转换为 Word 文件,请参阅有关如何使用 C将 HTML 转换为 Word 文档的文章。