本文介紹經過調用Spire.Cloud.Word.SDK提供的ConvertApi接口將Word轉換爲PDF、XPS、Epub、RTF以及將Docx轉爲Doc格式等。調用接口方法及步驟參考如下步驟:php
步驟一:dll文件獲取及導入。經過官網本地下載SDK文件包。(須在e-iceblue中國官網在線編輯板塊中註冊帳號並登陸)html
下載後,解壓文件,將Spire.Cloud.Word.Sdk.dll文件及其餘三個dll添加引用至VS程序;或者在程序中經過Nuget搜索下載,直接導入全部dll。dll引用結果以下圖所示:web
步驟二:App ID及Key獲取。在「個人應用」板塊中建立應用以得到App ID及App Key。api
步驟三:源文檔上傳。在「文檔管理」板塊,上傳源文檔。這裏能夠建文件夾,將文檔存放在文件夾下。不建文件夾時,源文檔及結果文檔直接保存在根目錄。本文示例中,建了兩個文件夾,分別用於存放源文檔及結果文檔。(雲平臺提供免費1 萬次調用次數和 2G 文檔內存)app
using System; using Spire.Cloud.Word.Sdk.Client; using Spire.Cloud.Word.Sdk.Api; namespace WordToPDF { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi對象 ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx";//源文檔 string format = "pdf";//轉換的目標文檔格式 string password = null;//源文檔 string folder = "input";//源文檔所在文件夾,若是沒有文件夾則爲null string storage = null;//使用冰藍雲配置的2G空間存貯文檔,可設置爲null string destFilePath = "output/WordToPDF.pdf";//結果文檔路徑(結果文檔保存在output文件夾下) //調用方法將Word轉爲PDF convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath); } } }
using System; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; namespace WordToXPS { class Program { static String appId = "App ID"; static String appKey = "APP Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi對象 ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文檔 string format = "xps";//轉換的目標文檔格式 string password = null;//源文檔密碼 string folder = "input";//源文檔的文件夾,若是沒有文件夾則爲null string storage = null;//使用冰藍雲配置的2G空間存貯文檔,可設置爲null string destFilePath = "output/WordToXPS.xps";//結果文檔路徑及名稱(結果文檔保存在output文件夾下) //調用方法將Word轉爲XPS convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath); } } }
using System; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; namespace WordToEpub { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi對象 ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文檔 string format = "epub";//轉換的目標文檔格式 string password = null;//源文檔密碼 string folder = "input";//源文檔的文件夾,若是沒有文件夾則爲null string storage = null;//使用冰藍雲配置的2G空間存貯文檔,可設置爲null string destFilePath = "output/WordToEpub.epub";//結果文檔路徑及名稱(結果文檔保存在output文件夾下) //調用方法將Word轉爲Epub convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath); } } }
using System; using Spire.Cloud.Word.Sdk.Client; using Spire.Cloud.Word.Sdk.Api; namespace WordToRTF { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi對象 ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文檔 string format = "rtf";//轉換的目標文檔格式 string password = null;//源文檔密碼 string folder = "input";//源文檔的文件夾,若是沒有文件夾則爲null string storage = null;//使用冰藍雲配置的2G空間存貯文檔,可設置爲null string destFilePath = "output/WordToRTF.rtf";//結果文檔路徑及名稱(結果文檔保存在output文件夾下) //調用方法將Word轉爲RTF convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath); } } }
using System; using Spire.Cloud.Word.Sdk.Client; using Spire.Cloud.Word.Sdk.Api; namespace DocxToDoc { class Program { static String appId = "App ID"; static String appKey = "APP Key"; static void Main(string[] args) { //配置App ID和App Key Configuration configuration = new Configuration(appId, appKey); //初始化ConvertApi對象 ConvertApi convertApi = new ConvertApi(configuration); string name = "Sample.docx"; //源文檔 string format = "doc";//轉換的目標文檔格式 string password = null;//源文檔密碼 string folder = "input";//源文檔的文件夾,若是沒有文件夾則爲null string storage = null;//使用冰藍雲配置的2G空間存貯文檔,可設置爲null string destFilePath = "output/DocxToDoc.doc";//結果文檔路徑及名稱(結果文檔保存在output文件夾下) //調用方法將Docx轉爲Doc convertApi.ConvertDocument(name, format, password, folder, storage, destFilePath); } } }
(本文完)spa