PDF Adding Watermark Tool Guide
Note:Before learning how to use different functions, we recommend that read the Request Workflow to know a basic PDF processing process. When using different functions, you can set their own special parameters when uploading files. Other basic steps are consistent.
PDF Add Watermark:
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": ""
}
Parameter | Description |
---|---|
type | Watermark type (text: text type watermark, image: image type watermark) |
scale | Zoom (image type attribute) |
opacity | Transparency:0~1 |
rotation | Rotation angle, a positive number means counterclockwise rotation |
targetPages | Page number, page number starts from 1, for example:1,2,4,6,9-11 |
vertalign | Vertical alignment(top、center、bottom) |
horizalign | Horizontal alignment(left、center、right) |
xoffset | Horizontal offset |
yoffset | Vertical offset |
content | Text |
textColor | Text color, for example:#FFFFFF |
front | Present on the front |
fullScreen | Whether to fill the entire page |
horizontalSpace | Horizontal spacing (supported only if --fullscreen exists) default value 50 |
verticalSpace | Vertical spacing (supported only if --fullscreen exists) default value 50 |
extension | Extended information, base64 encoding |
Java Example:
Replace apiKey with the publicKey obtained from the dashboard, file with the file you want to convert, and language with your preferred interface error prompt language type.
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();
}
}
Result:
File Type | Description |
---|---|
The PDF file after add watermarks |