轉帖|使用教程|編輯:李顯亮|2020-05-12 10:38:58.773|閱讀 207 次
概述:Spire.Cloud是一款幫助WEB網站或WEB應用系統輕松實現打開、編輯、保存和打印Office的軟件,是目前把Office應用到WEB平臺上的最全面的解決方案。 本文將講解如何使用Spire.Cloud.Word 添加 Word 水印(文本水印、圖片水印)
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實現與web應用程序對接的軟件嗎?好巧,冰藍公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開發接口,既能安全穩定地實現WEB網頁端在線查看、編輯Office文檔;又能在服務器端通過代碼調用接口簡單高效地實現讀寫Office文檔內容。
Spire.Cloud.Word提供了watermarksApi接口可用于添加水印,包括添加文本水印(SetTextWatermark)、圖片水印(SetImageWatermark),本文將對此做詳細介紹。
Spire.Cloud提供了四種語言的SDK(包括.NET、Java、python、PHP),你可以點擊下載Spire.Cloud Web SDK。
步驟1:dll文件獲取及引用。下載獲取Spire.Cloud.Word.SDK package,并將Spire.Cloud.Word.Sdk.dll及其依賴項的dll添加引用至程序(如下圖)
步驟2:ID及Key獲取。在冰藍云網頁注冊賬號并登陸,在“我的應用”板塊創建應用程序,獲得 App ID 及 App Key。
步驟3:文件路徑設置。在冰藍云網頁“我的文檔”板塊,分別建立input和output兩個文件夾,并將測試的Word文檔和圖片上傳至input文件夾下。通過VS代碼程序,生成的帶水印的Word文檔將保存至output文件夾下。
具體代碼操作方法,請參考以下內容。
示例1:添加文本水印
using Spire.Cloud.Word.Sdk; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; using Spire.Cloud.Word.Sdk.Model; using System; namespace txtwatermark { class Program { static String appId = "應用程序App ID"; static String appKey = "應用程序App Key"; static void Main(string[] args) { //配置賬號信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創建TablesApi實例 WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //設置文件夾、測試文檔、水印字樣及水印樣式等 string inputfolder = "input"; string storage = null; string password = null; var document = "testfile.docx"; string name = document; TextWatermark body = new TextWatermark("Watermark") { Layout = TextWatermark.LayoutEnum.Diagonal, Font = new Font(60, "宋體") { Color = new Color(100, 100, 100) } }; //調用SetTextWatermark接口添加文本水印到Word文檔 ,并保存到指定文件路徑 string destFilePath = "output/SetTextWatermark.docx"; watermarksApi.SetTextWatermark(name, body, inputfolder, storage, password, destFilePath); } } }
文本水印添加效果:
示例2:添加圖片水印
using Spire.Cloud.Word.Sdk; using Spire.Cloud.Word.Sdk.Api; using Spire.Cloud.Word.Sdk.Client; using System; namespace ImgWatermark { class Program { static String appId = "應用程序App ID "; static String appKey = "應用程序App Key "; static void Main(string[] args) { //配置賬號信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創建TablesApi實例 WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //設置文件夾、測試文檔、用于水印的圖片及水印樣式等 string inputfolder = "input"; string storage = null; int scaling = 120; bool washout = true; string password = null; var document = "testfile.docx"; string name = document; string imagePath = "input/logo.png"; //調用SetImageWatermark接口添加圖片水印到Word文檔 ,并保存到指定文件路徑 string destFilePath = "output/SetImageWatermark.docx"; watermarksApi.SetImageWatermark(name, imagePath, inputfolder, storage, scaling, washout, password, destFilePath); } } }
圖片水印添加效果:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn