Spire.Cloud是一款帮助WEB网站或WEB应用系统轻松实现打开、编辑、保存和打印Office的软件,是目前把Office应用到WEB平台上的最全面的解决方案。 本文将讲解如何使用Spire.Cloud.Word 添加 Word 水印(文本水印、图片水印)
你在寻找一款既能在线编辑office文件,又能实现与web应用程序对接的软件吗巧,冰蓝公司最新推出Spire.Cloud,搭载了基于云端的Office在线编辑器和WEBAPI开发接口,既能安全稳定地实现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); } }}
图片水印添加效果:
是E-iceblue官方友好合作伙伴,如果您对Spire
.Cloud感兴趣或需要临时License,可以联系在线客服了解具体授权价格和使用机制。标签:
来源:慧都
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!