Skip to content

Advanced PDF Tool Guides

Watermark Tool Guide

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": ""
}
CodeDescription
typeWatermark type (text: text type watermark, image: image type watermark)
scaleZoom (image type attribute)
opacityTransparency:0~1
rotationRotation angle, a positive number means counterclockwise rotation
targetPagesPage number, page number starts from 1, for example:1,2,4,6,9-11
vertalignVertical alignment(top、center、bottom)
horizalignHorizontal alignment(left、center、right)
xoffsetHorizontal offset
yoffsetVertical offset
contentText
textColorText color, for example:#FFFFFF
frontPresent on the front
fullScreenWhether to fill the entire page
horizontalSpaceHorizontal spacing (supported only if --fullscreen exists) default value 50
verticalSpaceVertical spacing (supported only if --fullscreen exists) default value 50
extensionExtended information, base64 encoding

Java Example

  1. Authentication

    You need to replace and with accessToken in the publicKey and secretKey authentication getback values you get from the console.

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/oauth/token' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "publicKey": "publicKey",
        "secretKey": "secretKey"
    }'
    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 = RequestBody.create(mediaType, "{\n    \"publicKey\": \"{{public_key}}\",\n    \"secretKey\": \"{{secret_key}}\"\n}");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/oauth/token")
          .method("POST", body)
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  2. Create Task

    You need to replace with the accessToken which was obtained from the previous step, and replace with the language type you want to display the error information. After replacing them, you will get the taskId in the response data.

    curl
     curl --location --request GET 'https://api-server.compdf.com/server/v1/task/pdf/addWatermark' \
     --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/pdf/addWatermark?language={{language}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  3. Upload Files

    Replace with the file you want to convert, with the taskId obtained in the previous step, with the language type you want to display the error information, and with the accessToken obtained in the first step.

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/file/upload' \
    --header 'Authorization: Bearer accessToken' \
    --form 'file=@"test.pdf"' \
    --form 'taskId="taskId"' \
    --form 'password=""' \
    --form 'parameter="{\"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\":\"1\",\"fullScreen\":\"1\",\"horizontalSpace\":\"10\",\"verticalSpace\":\"10\",\"extension\":\"\"}"' \
    --form '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("taskId","{{taskId}}")
          .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/file/upload")
          .method("POST", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  4. Process Files

    Replace with the taskId you obtained from the Create task, and with the accessToken obtained in the first step, and replace with the language type you want to display the error information.

    curl
     curl --location -g --request GET 'https://api-server.compdf.com/server/v1/execute/start?taskId=taskId' \
     --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
       Request request = new Request.Builder()
         .url("https://api-server.compdf.com/server/v1/execute/start?taskId={{taskId}}&language={{language}}")
         .method("GET", body)
         .addHeader("Authorization", "Bearer {{accessToken}}")
         .build();
       Response response = client.newCall(request).execute();
     }
    }
  5. Get Task Information

    Replace with you from Create the task obtained in the taskId, replaced by access_token obtained in the first step.

    curl
    curl --location -g --request GET 'https://api-server.compdf.com/server/v1/task/taskInfo?taskId=taskId' \
    --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/taskInfo?taskId={{taskId}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }

Result

File TypeDescription
.pdfThe PDF file after add watermarks

PDF Delete 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.

Example

  1. Authentication

    You need to replace and with accessToken in the publicKey and secretKey authentication getback values you get from the console.

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/oauth/token' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "publicKey": "publicKey",
        "secretKey": "secretKey"
    }'
    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 = RequestBody.create(mediaType, "{\n    \"publicKey\": \"{{public_key}}\",\n    \"secretKey\": \"{{secret_key}}\"\n}");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/oauth/token")
          .method("POST", body)
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  2. Create Task

    You need to replace with the accessToken which was obtained from the previous step, and replace with the language type you want to display the error information. After replacing them, you will get the taskId in the response data.

    curl
     curl --location --request GET 'https://api-server.compdf.com/server/v1/task/pdf/delWatermark' \
     --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/pdf/delWatermark?language={{language}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  3. Upload Files

    Replace with the file you want to convert, with the taskId obtained in the previous step, with the language type you want to display the error information, and with the accessToken obtained in the first step.

    curl
    curl --location --request POST 'https://api-server.compdf.com/server/v1/file/upload' \
    --header 'Authorization: Bearer accessToken' \
    --form 'file=@"test.pdf"' \
    --form 'taskId="taskId"' \
    --form 'password=""' \
    --form '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("taskId","{{taskId}}")
          .addFormDataPart("language","{{language}}")
          .addFormDataPart("password","")
          .build();
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/file/upload")
          .method("POST", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }
  4. Process Files

    Replace with the taskId you obtained from the Create task, and with the accessToken obtained in the first step, and replace with the language type you want to display the error information.

    curl
     curl --location -g --request GET 'https://api-server.compdf.com/server/v1/execute/start?taskId=taskId' \
     --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
       Request request = new Request.Builder()
         .url("https://api-server.compdf.com/server/v1/execute/start?taskId={{taskId}}&language={{language}}")
         .method("GET", body)
         .addHeader("Authorization", "Bearer {{accessToken}}")
         .build();
       Response response = client.newCall(request).execute();
     }
    }
  5. Get Task Information

    Replace with you from Create the task obtained in the taskId, replaced by access_token obtained in the first step.

    curl
    curl --location -g --request GET 'https://api-server.compdf.com/server/v1/task/taskInfo?taskId=taskId' \
    --header 'Authorization: Bearer accessToken'
    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 = RequestBody.create(mediaType, "");
        Request request = new Request.Builder()
          .url("https://api-server.compdf.com/server/v1/task/taskInfo?taskId={{taskId}}")
          .method("GET", body)
          .addHeader("Authorization", "Bearer {{accessToken}}")
          .build();
        Response response = client.newCall(request).execute();
      }
    }

Result

File TypeDescription
.pdfThe PDF file after delete watermarks