这篇简单的文章介绍了 使用 NET REST API 将 DOCX 转换为 EPUB 的机制。 Aspose.Words for .NET Cloud SDK 可用于将 DOCX 文件导出为 EPUB 文件。如果您想使用 C# 低代码 API 创建 Word DOCX 到 EPUB 转换器,请按照以下给出的步骤操作,并使用工作示例代码尝试该功能。
先决条件
- 创建帐户并获取 API 凭据
- 下载 Aspose.Words Cloud SDK for .NET to perform DOCX to EPUB conversion
- 使用上述 SDK 设置 C# 项目以将 DOCX 转换为 EPUB
使用 C# 低代码 API 将 Word DOC 转换为 EPUB 的步骤
- 设置 API 的客户端 ID 和客户端密钥以将 DOCX 转换为 EPUB
- 使用客户端凭据实例化 WordsAPI 类的对象
- 指定输入 DOCX 和输出 EPUB 文件
- 读取文件流中的输入 DOCX 文件并将其作为参数传递给 ConvertDocumentRequest 类实例
- 调用 ConvertDocument 方法使用 REST API 将 DOCX 转换为 EPUB
- 将转换后的EPUB文件保存到本地磁盘
上述步骤可确保使用 REST API* 快速将 *DOCX 转换为 EPUB。该过程将首先使用 Aspose.Words for .NET REST SDK 并通过提供订阅的借出标识符和秘密值来获取 WordsApi 的实例。将使用文件流从磁盘加载源 DOCX 文件,并使用 ConvertDocument() 方法在云端完成 Word 到 EPUB 的转换,并返回可保存在本地磁盘上的 EPUB 文件。
使用 NET REST API 将 DOC 转换为 EPUB 的代码
using Aspose.Words.Cloud.Sdk; | |
using Aspose.Words.Cloud.Sdk.Model.Requests; | |
using System; | |
using System.IO; | |
namespace WordsSample.Words | |
{ | |
public class DocxToEpub | |
{ | |
public void ConvertDocxToEpub() | |
{ | |
try | |
{ | |
var apiClient = new Configuration(); | |
apiClient.ClientSecret = "Client Secret"; | |
apiClient.ClientId = "Client ID"; | |
//Create SDK object | |
WordsApi wordsApi = new WordsApi(apiClient); | |
string localPath = @"C:\Words\"; | |
string inputFile = "Test.docx"; | |
string outputFile = "DOCXToEPUB.epub"; | |
string outputFormat = "epub"; | |
//Read input file to bytes array | |
var inpuFileStream = File.Open(localPath + '/' + inputFile, FileMode.Open); | |
inpuFileStream.Position = 0; | |
//create conversion request object with input and output files | |
ConvertDocumentRequest convertDocRequest = new ConvertDocumentRequest(inpuFileStream, outputFormat, null, null, null, null, null, null, null); | |
var conversionTask = wordsApi.ConvertDocument(convertDocRequest); | |
conversionTask.Wait(); | |
var outputFileStream = conversionTask.Result; | |
outputFileStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFile + "." + outputFormat)) | |
{ | |
outputFileStream.Seek(0, SeekOrigin.Begin); | |
outputFileStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
此示例代码为使用 C# REST API* 开发 *Word 文档到 EPUB 转换器提供了基础。您可以选择在转换过程中设置其他参数,例如输出文件名、输出文档的路径以及源文件的密码。 DOCX 到 EPUB 转换 的此功能可与支持此 SDK 的任何操作系统上的任何无代码或低代码应用程序一起使用。
在本主题中,我们了解了使用 C# REST API 将 DOCX 转换为 EPUB。如果您有兴趣为 DOCX 文件渲染 BMP,请参阅有关如何使用 .NET REST API 将 DOCX 转换为 BMP的文章。