这个简短的教程介绍了使用 NET REST API 将 DOC 转换为 EPUB 的过程。我们将使用 Aspose.Words for .NET Cloud SDK 将 Word DOC 文件导出到 EPUB 文件。如果您想使用 C# 低代码 API 开发 Word DOC 到 EPUB 转换器,请按照本文中给出的步骤操作,并使用正在运行的示例代码尝试该功能。
先决条件
- 创建帐户并获取 API 凭据
- 下载 Aspose.Words Cloud SDK for Dotnet
- 使用上述 SDK 设置 C# 项目
使用 C# 低代码 API 将 Word DOC 转换为 EPUB 的步骤
- 为将 DOC 转换为 EPUB 的 API 设置客户端 ID 和客户端密钥
- 使用客户端凭据创建 WordsAPI 类的实例
- 指定输入和输出文件
- 读取输入DOC文件并上传到云存储
- 调用 ConvertDocument 方法使用 REST API 将 DOC 转换为 EPUB
- 将输出的 EPUB 文件保存在本地磁盘上
上述步骤可确保使用 REST API* 顺利地将 *DOCX 转换为 EPUB。该过程将首先使用 Aspose.Words for .NET REST SDK 并通过提供订阅的借出标识符和秘密值来创建 WordsApi 实例。将从磁盘访问源 Word 文件,并使用 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 WordsToEpub | |
{ | |
public void ConvertWordToEpub() | |
{ | |
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 = "Test1.doc"; | |
string outputFile = "DOCToEPUB.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 convertDocumentRequest = new ConvertDocumentRequest(inpuFileStream, outputFormat, null, null, null, null, null, null, null); | |
var conversionTask = wordsApi.ConvertDocument(convertDocumentRequest); | |
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 转换器提供了基础。您可以在转换过程中设置其他参数,例如输出文档的路径、输出文件名、编码详细信息(如果输入文件是 HTML 或 TXT 文件)以及源文件的密码。 DOC 到 EPUB 转换 的此功能可与支持此 SDK 的任何操作系统上的任何无代码或低代码应用程序一起使用。
您还可以在以下页面上查看另一个类似的功能:使用 .NET REST API 将 DOCX 转换为 BMP。