轉(zhuǎn)帖|使用教程|編輯:李顯亮|2020-05-12 10:38:58.773|閱讀 207 次
概述:Spire.Cloud是一款幫助WEB網(wǎng)站或WEB應(yīng)用系統(tǒng)輕松實(shí)現(xiàn)打開、編輯、保存和打印Office的軟件,是目前把Office應(yīng)用到WEB平臺(tái)上的最全面的解決方案。 本文將講解如何使用Spire.Cloud.Word 添加 Word 水印(文本水印、圖片水印)
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實(shí)現(xiàn)與web應(yīng)用程序?qū)拥能浖幔亢们桑{(lán)公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開發(fā)接口,既能安全穩(wěn)定地實(shí)現(xiàn)WEB網(wǎng)頁端在線查看、編輯Office文檔;又能在服務(wù)器端通過代碼調(diào)用接口簡單高效地實(shí)現(xiàn)讀寫Office文檔內(nèi)容。
Spire.Cloud.Word提供了watermarksApi接口可用于添加水印,包括添加文本水印(SetTextWatermark)、圖片水印(SetImageWatermark),本文將對(duì)此做詳細(xì)介紹。
Spire.Cloud提供了四種語言的SDK(包括.NET、Java、python、PHP),你可以點(diǎn)擊下載Spire.Cloud Web SDK。
步驟1:dll文件獲取及引用。下載獲取Spire.Cloud.Word.SDK package,并將Spire.Cloud.Word.Sdk.dll及其依賴項(xiàng)的dll添加引用至程序(如下圖)
步驟2:ID及Key獲取。在冰藍(lán)云網(wǎng)頁注冊(cè)賬號(hào)并登陸,在“我的應(yīng)用”板塊創(chuàng)建應(yīng)用程序,獲得 App ID 及 App Key。
步驟3:文件路徑設(shè)置。在冰藍(lán)云網(wǎng)頁“我的文檔”板塊,分別建立input和output兩個(gè)文件夾,并將測試的Word文檔和圖片上傳至input文件夾下。通過VS代碼程序,生成的帶水印的Word文檔將保存至output文件夾下。
具體代碼操作方法,請(qǐng)參考以下內(nèi)容。
示例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 = "應(yīng)用程序App ID"; static String appKey = "應(yīng)用程序App Key"; static void Main(string[] args) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建TablesApi實(shí)例 WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //設(shè)置文件夾、測試文檔、水印字樣及水印樣式等 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) } }; //調(diào)用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 = "應(yīng)用程序App ID "; static String appKey = "應(yīng)用程序App Key "; static void Main(string[] args) { //配置賬號(hào)信息 Configuration wordConfiguration = new Configuration(appId, appKey); //創(chuàng)建TablesApi實(shí)例 WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration); //設(shè)置文件夾、測試文檔、用于水印的圖片及水印樣式等 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"; //調(diào)用SetImageWatermark接口添加圖片水印到Word文檔 ,并保存到指定文件路徑 string destFilePath = "output/SetImageWatermark.docx"; watermarksApi.SetImageWatermark(name, imagePath, inputfolder, storage, scaling, washout, password, destFilePath); } } }
圖片水印添加效果:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn