这篇基础文章介绍了使用 NET REST API 将 Word 转换为 SVG 的过程。 Aspose.Words for .NET Cloud SDK 提供了一个简单的界面,可用于将 Word DOC 文件导出到 SVG 文件。如果您有兴趣使用 C# 低代码 API 开发 Word DOC 到 SVG 转换器,您可以遵循本文中共享的简单指南,并尝试使用工作示例代码探索该功能。
先决条件
- 创建免费的 Aspose.Cloud 帐户并获取 API 凭据 将 Word 转换为 SVG
- 下载 Aspose.Words Cloud SDK for .NET 执行 DOCX 到 SVG 转换
- 使用上述 SDK 设置 C# 项目以进行 Word 到 SVG 转换
使用 C# 低代码 API 将 Word DOC 转换为 SVG 的步骤
- 为 API 设置客户端 ID 和客户端密钥以将 Word Doc 转换为 SVG
- 使用您的客户端凭据实例化 WordsAPI 类的对象
- 设置输入Word和输出SVG文件名
- 访问示例 DOCX 文件并将其转换为文件流
- 使用 ConvertDocument 方法使用 REST API 将 DOCX 转换为 SVG
- 将生成的SVG文件保存到本地磁盘
上述步骤指导使用 REST API 实现 *DOCX 到 SVG 的转换,该过程是通过使用 Aspose.Words for .NET REST SDK 开始的,并使用云应用程序标识符和秘密值实例化 WordsApi 类。示例 Word DOCX 文件将通过文件流从磁盘打开,并由 ConvertDocument() 方法使用,通过返回可保存在磁盘上的输出 SVG 文件流来完成云中的 Word 到 SVG 转换过程。
使用 NET REST API 将 DOC 转换为 SVG 的代码
using Aspose.Words.Cloud.Sdk; | |
using Aspose.Words.Cloud.Sdk.Model.Requests; | |
using System; | |
using System.IO; | |
namespace WordsSample.Words | |
{ | |
public class WordsToSvg | |
{ | |
public void ConvertWordToSvgAsync() | |
{ | |
try | |
{ | |
var apiClient = new Configuration(); | |
apiClient.ClientSecret = ""; | |
apiClient.ClientId = ""; | |
//Create SDK object | |
WordsApi wordsApi = new WordsApi(apiClient); | |
string localPath = @"C:\Words\"; | |
string inputFile = "Test1.docx"; | |
string outputFile = "DOCXToSvg.svg"; | |
string outputFormat = "svg"; | |
//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 文档到 SVG 转换器的框架。您还可以在转换过程中设置其他参数,包括输出文档的路径、添加行间距和输出文件名。 DOC 到 SVG 转换的此功能可与支持 .NET Framework 的任何操作系统上的任何无代码或低代码应用程序一起使用。
在本文中,我们介绍了使用 NET REST API 实现Word 到 SVG 转换的过程。如果您对 Word 到 RTF 的转换感兴趣,请参阅有关如何使用 NET REST API 将 Word 转换为 RTF的文章。