PDF添加水印工具使用指南
注意:在学习使用不同函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。
PDF 添加水印:
java
{
"type": "text",
"scale": "1",
"opacity": "0.5",
"rotation": "0.785",
"targetPages": "1-2",
"vertalign": "center",
"horizalign": "left",
"xoffset": "100",
"yoffset": "100",
"content": "test",
"textColor": "#59c5bb",
"front": "",
"fullScreen": "111",
"horizontalSpace": "10",
"verticalSpace": "10",
"extension": ""
}
参数 | 说明 |
---|---|
type | 水印类型(text:文本类型水印,image:图片类型水印) |
scale | 缩放(图片类型属性) |
opacity | 透明度:0~1 |
rotation | 旋转角度,正数表示逆时针旋转 |
targetPages | 页码,页码从1开始,如:1,2,4,6,9-11 |
vertalign | 垂直对齐(top、center、bottom) |
horizalign | 水平对齐(left、center、right) |
xoffset | 水平偏移 |
yoffset | 垂直偏移 |
content | 文本 |
textColor | 文本颜色,如:#FFFFFF |
front | 显示在最前面 |
fullScreen | 是否填满整个页面 |
horizontalSpace | 水平间距(仅当存在 --fullscreen 时才支持)默认值 50 |
verticalSpace | 垂直间距(仅当存在 --fullscreen 时才支持)默认值 50 |
extension | 扩展信息,base64 编码 |
Java 示例:
您需要将 apiKey 替换为您从控制台获取的 publicKey ,将 file 替换为您要转换的文件 ,language 替换为您想要的接口错误提示语言类型。
java
import java.io.*;
import okhttp3.*;
public class main {
public static void main(String []args) throws IOException{
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("file","{{file}}",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("<file>")))
.addFormDataPart("language","{{language}}")
.addFormDataPart("password","")
.addFormDataPart("parameter","{ \"type\": \"image\", \"scale\": \"1\", \"opacity\":\"0.5\", \"rotation\":\"0.785\", \"targetPages\":\"1-5\", \"vertalign\":\"center\", \"horizalign\":\"left\", \"xoffset\":\"100\", \"yoffset\":\"100\", \"front\":\"\", \"fullScreen\":\"111\", \"horizontalSpace\":\"10\", \"verticalSpace\":\"10\", \"extension\":\"\"}")
.addFormDataPart("image","",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("")))
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v1/process/pdf/addWatermark")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}
结果:
文件类型 | 说明 |
---|---|
添加水印后的 PDF 文件 |