云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印

Spire.Cloud提供了四种语言的SDK(包括.NET、Java、python、PHP),你可以Spire.Cloud Web SDK

步骤1:dll文件获取及引用。下载获取Spire.Cloud.Word.SDK package,并将Spire.Cloud.Word.Sdk.dll及其依赖项的dll添加引用至程序(如下图)

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印

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

文本水印添加效果:

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印

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

图片水印添加效果:

云端Office处理工具Spire.Cloud.Word基础教程:添加 Word 水印

是E-iceblue官方友好合作伙伴,如果您对Spire

.Cloud感兴趣或需要临时License,可以联系在线客服了解具体授权价格和使用机制。
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年4月9日
下一篇 2020年4月9日

相关推荐

发表回复

登录后才能评论