操作 Word 文档中的水印,包括获取文字水印属性,设置文字/图片水印,删除水印。
接口方法 1:getTextWatermarkFormat() 获取文字水印的属性
HTTP 请求方法:GET
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/watermarks/textProperties
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace GetTextWatermarkFormat
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
static void Main(string[] args)
{
string fileName = "getTextWatermarkFormat.docx";
string folder = "input";
string storage = null;
string password = null;
var response = watermarksApi.GetTextWatermarkFormat(fileName, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.WatermarksApi;
import spire.cloud.word.sdk.client.model.*;
public class GetTextWatermarkFormat {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String fileName = "getTextWatermarkFormat.docx";
String folder = "input";
String storage = null;
String password = null;
TextWatermark response = watermarksApi.getTextWatermarkFormat(fileName, folder, storage, password);
}
}
接口方法 2:setTextWatermark() 设置文字水印
HTTP 请求方法:PUT
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/watermarks/text
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
body | 是 | object | 水印文字的信息 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Model;
namespace SetTextWatermark
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
static void Main(string[] args)
{
string name = "setTextWatermark.docx";
string folder = "input";
string storage = null;
string password = null;
TextWatermark body = new TextWatermark("E-iceblue")
{
Layout = TextWatermark.LayoutEnum.Horizontal,
Font = new Font(60, "Arial")
{
Color = new Color(100, 100, 100)
}
};
string destFilePath = "output/setTextWatermark_output.docx";
watermarksApi.SetTextWatermark(name, body, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.WatermarksApi;
import spire.cloud.word.sdk.client.model.*;
public class SetTextWatermark {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "setTextWatermark.docx";
String folder = "input";
String storage = null;
String password = null;
TextWatermark tempVar = new TextWatermark("E-iceblue");
tempVar.setLayout(TextWatermark.LayoutEnum.HORIZONTAL);
Color color = new Color(100, 100, 100);
Font font = new Font("Cooper Black", 60f, color);
tempVar.setFont(font);
TextWatermark body = tempVar;
String destFilePath = "output/setTextWatermark_output.docx";
watermarksApi.setTextWatermark(name, body, destFilePath, folder, storage, password);
}
}
接口方法 3:setImageWatermarkInRequest() 设置图片水印
HTTP 请求方法:PUT
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/watermarks/imageInRequest
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
using System.IO;
namespace SetImageWatermarkInRequest
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
static void Main(string[] args)
{
string name = "watermark.docx";
string inputFilePath = "D:/inputFile/Background.png";
Stream inputImage = new FileStream(inputFilePath, FileMode.Open);
string folder = "input";
string storage = null;
int scaling = 120;
bool washout = false;
string password = null;
string destFilePath = "output/setImageWatermarkInRequest_output.docx";
watermarksApi.SetImageWatermarkInRequest(name, inputImage, destFilePath, folder, storage, scaling, washout, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.WatermarksApi;
import java.io.File;
public class SetImageWatermarkInRequest {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String name = "watermark.docx";
String inputFilePath = "D:/inputFile/Background.png";
File inputImage = new File(inputFilePath);
String folder = "input";
String storage = null;
Integer scaling = 120;
Boolean washout = false;
String password = null;
String destFilePath = "output/setImageWatermarkInRequest_output.docx";
watermarksApi.setImageWatermarkInRequest(name, inputImage, destFilePath, folder, storage, scaling, washout, password);
}
}
接口方法 4: setImageWatermark() 设置图片水印
HTTP 请求方法:PUT
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/watermarks/image
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
imagePath | 是 | string | 图片路径 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 | |
scaling | 否 | integer | 图片缩放比例 | |
washout | 否 | boolen | true, false | 是否设置褪色 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace SetImageWatermark
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
static void Main(string[] args)
{
string fileName = "setImageWatermark.docx";
string imagePath = "images/Background.png";
string folder = "input";
string storage = null;
int scaling = 120;
bool washout = true;
string password = null;
string destFilePath = "output/setImageWatermark_output.docx";
watermarksApi.SetImageWatermark(fileName, imagePath, destFilePath, folder, storage, scaling, washout, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.WatermarksApi;
public class SetImageWatermark {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String fileName = "setImageWatermark.docx";
String imagePath = "images/Background.png";
String folder = "input";
String storage = null;
Integer scaling = 120;
Boolean washout = true;
String password = null;
String destFilePath = "output/setImageWatermark_output.docx";
watermarksApi.setImageWatermark(fileName, imagePath, destFilePath,folder, storage, scaling, washout, password);
}
}
接口方法 5:deleteWatermark() 删除水印
HTTP 请求方法:DELETE
请求 URL:https://api.e-iceblue.cn/v1/word/document/{name}/watermarks/deleteWatermark
请求参数:
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
name | 是 | string | 原文档名称 | |
folder | 否 | string | 存放原文档的文件夹,没有则为null | |
storage | 否 | string | 文档存储空间,使用冰蓝云配置的2G空间存贮文档,可设置为null | |
password | 否 | string | 原文档密码,没有则为null | |
imagePath | 是 | string | 图片路径 | |
destFilePath | 是 | string | 结果文档的存贮路径,如果省略该参数,则默认存到根目录 |
代码示例:
- .NET
- Java
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace DeleteWatermark
{
class Program
{
static string appId = "your id";
static string appKey = "your key";
static string baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
static void Main(string[] args)
{
string fileName = "deleteWatermark.docx";
string folder = "input";
string storage = null;
string password = null;
string destFilePath = "output/deleteWatermark_output.docx";
watermarksApi.DeleteWatermark(fileName, destFilePath, folder, storage, password);
}
}
}
import spire.cloud.word.sdk.client.*;
import spire.cloud.word.sdk.client.api.WatermarksApi;
public class DeleteWatermark {
static String appId = "your id";
static String appKey = "your key";
static String baseUrl = "https://api.e-iceblue.cn";
static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl);
static WatermarksApi watermarksApi = new WatermarksApi(wordConfiguration);
public static void main(String[] args) throws ApiException {
String fileName = "deleteWatermark.docx";
String folder = "input";
String storage = null;
String password =null;
String destFilePath = "output/deleteWatermark_output.docx";
watermarksApi.deleteWatermark(fileName, destFilePath, folder, storage, password);
}
}