C# 將Word轉為PDF、XPS、Epub、RTF(基於Spire.Cloud.Word.SDK)

来源:https://www.cnblogs.com/Yesi/archive/2020/01/13/12187601.html
-Advertisement-
Play Games

本文介紹通過調用Spire.Cloud.Word.SDK提供的ConvertApi介面將Word轉換為PDF、XPS、Epub、RTF以及將Docx轉為Doc格式等。調用介面方法及步驟參考以下步驟: 步驟一:dll文件獲取及導入。通過官網本地下載SDK文件包。(須在e-iceblue中國官網線上編輯 ...


本文介紹通過調用Spire.Cloud.Word.SDK提供的ConvertApi介面將Word轉換為PDF、XPS、Epub、RTF以及將Docx轉為Doc格式等。調用介面方法及步驟參考以下步驟:

步驟一:dll文件獲取及導入。通過官網本地下載SDK文件包。(須在e-iceblue中國官網線上編輯板塊中註冊賬號並登錄)

 

下載後,解壓文件,將Spire.Cloud.Word.Sdk.dll文件及其他三個dll添加引用至VS程式;或者在程式中通過Nuget搜索下載,直接導入所有dll。dll引用結果如下圖所示:

 

步驟二:App ID及Key獲取在“我的應用”板塊中創建應用以獲得App ID及App Key。

步驟三:源文檔上傳。在“文檔管理”板塊,上傳源文檔。這裡可以建文件夾,將文檔存放在文件夾下。不建文件夾時,源文檔及結果文檔直接保存在根目錄。本文示例中,建了兩個文件夾,分別用於存放源文檔及結果文檔。(雲平臺提供免費1 萬次調用次數和 2G 文檔記憶體)

 

C# 代碼示例

1. WordPDF

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);
        }
    }
}

 

2. WordXPS

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);
        }
    }
}

 

3. WordEpub

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);
        }
    }
}

 

4. WordRTF

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);
        }
    }
}

 

5. DocxDoc

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);
        }
    }
}

 

(本文完)


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 原文: "https://devblogs.microsoft.com/dotnet/configureawait faq/" .NET 在七多年前在語言和類庫添加了 。在那個時候,它像野火一樣流行,不僅遍及.NET生態系統,而且還可以以多種其他語言和框架進行複製。在利用非同步的其他語言構造,提供非同步 ...
  • 前言 在我們開發中可能需要設計一次性應用程式,這些實用程式可以利用接近原始源代碼的優勢,但可以在與主Web應用程式完全獨立的安全性上下文中啟動。具體在 [管理過程] (https://12factor.net/admin processes)中也已經列出了原因。 創建控制台應用 打開命令提示符,創建 ...
  • 說到驗證,那就需要做三件事: 定義驗證規則 按驗證規則進行檢查 報告驗證的錯誤。在把錯誤報告給API消費者的時候,報告里並不包含到底是服務端還是API消費者引起的錯誤,這是狀態碼的工作。而通常響應的Body裡面會包含一組驗證錯誤信息,API消費者可以把這些信息展示給API消費者的用戶。 定義驗證規則 ...
  • var url = data.url, params = data.params, try_times = data.try_times , async = data.sync == 'false' ? false : true; $.ajax({ url: url, type: "POST", t ...
  • 伴隨著dotnet core的不斷迭代,我們在享受.net性能上的提升之外,還收穫了許許多多新出現的API。不知您有沒有發現,有這樣一個類型在開始逐漸出現在我們的視野中 ———— ValueTask ...
  • 問題描述 最近在使用ef core連接oracle的發現Find、FirstOrDefault、Skip Task分頁等等方法執行失敗。使用的是docker安裝的oracle11,錯誤如下圖: 解決辦法 使用builder.UseOracleSQLCompatibility("11")方法來指定or ...
  • 一、什麼是Lock? Lock——字面上理解就是鎖上;鎖住;把……鎖起來的意思; 為什麼要鎖?要鎖乾什麼?——回到現實中可想象到,這個衛生間我要上,其他人不要進來!(所以我要鎖住門);又或者土味情話所言,我要把你鎖在我的心裡,然後在裡面加個無限迴圈語句,不給你出來,也不被別人所得,你只能是我的,哈哈 ...
  • 微信公眾號: "Dotnet9" ,網站: "Dotnet9" ,問題或建議: "請網站留言" , 如果對您有所幫助: "歡迎贊賞" 。 C WPF從RIOT API獲取數據(RIOT代表作品《英雄聯盟》) 閱讀導航 1. 本文背景 2. 代碼實現 3. 本文參考 1. 本文背景 RIOT(拳頭)是 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...