Skip to content

Compare Documents

Content Comparison

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.

Compare PDF content (Include text and images):

  • For one task, you must upload two PDF files. If isSaveTwo is set to "1", the processing result will be in a .zip file, which contains the comparison result files of the two PDFs.
  • For the same task, two PDF files must be uploaded. If isSaveTwo is set to "0", the processing result will be in a .pdf file, where the comparison results of the two files are combined into this file.
java
{
    "isSaveTwo": "0",
    "imgCompare": "1",
    "textCompare": "1",
    "replaceColor": "#93B9FD",
    "insertColor": "#C0FFEC",
    "deleteColor": "#FBBDBF"
}

Needed Parameters

isSaveTwo: Specify whether to generate two output files during content comparison: 1 for yes, 0 for no (default value is 0).

imgCompare: Specify whether to enable image comparison: 1 for yes, 0 for no (default value is 1).

textCompare: Specify whether to enable text comparison: 1 for yes, 0 for no (default value is 1).

replaceColor: Define the color for the replaced content (default value is #93B9FD).

insertColor: Define the color for the inserted content (default value is #C0FFEC).

deleteColor: Define the color for the deleted content (default value is #FBBDBF).

Example

  1. Authorization

    You need to replace and with the publicKey and secretKey obtained from the console in the authentication response, and use the accessToken.

    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 obtained from the previous step, and replace with the desired interface and task error message language type. After a successful request, you will receive the taskId from the response.

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

    Replace with the file you want to convert, replace with the taskId obtained from the previous step, replace with the desired interface error message language type, and replace with the accessToken obtained from 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="{ \"imgCompare\":\"1\", \"isSaveTwo\":\"0\", \"textCompare\":\"1\", \"replaceColor\":\"#FF0000\", \"insertColor\":\"#00FF00\", \"deleteColor\":\"#0000FF\"}"'
    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","{ \"imgCompare\": \"1\", \"isSaveTwo\": \"0\", \"textCompare\": \"1\", \"replaceColor\": \"#FF0000\", \"insertColor\": \"#00FF00\", \"deleteColor\":\"#0000FF\" }")
          .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. Execute task

    Replace with the taskId obtained from the Create task step, replace with the access_token obtained from the first step, and replace with the desired interface error message language type.

    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 the taskId obtained from the Create task step, and replace with the access_token obtained from 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 typeFile description
.pdf or .zipResult file of PDF content comparison

Overlay Comparison

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 file overlay comparison:

  • In one task, two files must be uploaded.
java
{
    "inTransparency": "0.5",
    "newTransparency": "0.5",
    "coverType": "0",
    "inColor": "#FBBDBF",
    "newColor": "#93B9FD"
}

Needed Parameters

inTransparency: Adjust the transparency of the old comparing file. (Range: 0 to 1, default value: 0.5)

newTransparency: Adjust the transparency of the new comparing file. (Range: 0 to 1, default value: 0.5)

coverType: Set the blend mode (Default value is 0. 0 represents Normal).(0: Normal, 1: Multiply, 2: Screen, 3: Overlay, 4: Darken, 5: Lighten, 6: ColorDodge, 7: ColorBurn, 8: HardLight, 9: SoftLight, 10: Difference, 11: Exclusion, 12: Hue, 13: Saturation, 14: Colour, 15: Luminosity)

inColor: Set the color of the old comparing file. Default value: #FBBDBF)

newColor: Set the color of the new comparing file. (Default value: #93B9FD)

Example

  1. Authorization

    You need to replace and with the publicKey and secretKey obtained from the console and use the accessToken from the authentication response.

    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 obtained from the previous step, replace with the desired interface and task error message language type, and after successful completion, obtain the taskId from the response.

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

    Replace with the file you want to convert, replace with the taskId obtained from the previous step, replace with the desired interface error message language type, and replace with the accessToken obtained from 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="{ \"inTransparency\":\"0.5\", \"newTransparency\":\"0.5\", \"coverType\":\"0\", \"inColor\":\"#FBBDBF\", \"newColor\":\"#93B9FD\"}"'
    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","{ \"inTransparency\":\"0.5\", \"newTransparency\":\"0.5\", \"coverType\":\"0\", \"inColor\":\"#FBBDBF\", \"newColor\":\"#93B9FD\"}")
          .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. Execute task

    Replace with the taskId obtained from the Create task step, replace with the access_token obtained in the first step, and replace with the desired interface error message language type.

    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 the taskId obtained from the Create task step, and replace with the 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 typeFile description
.pdfResult file of overlay comparison