Skip to content

文档对比工具使用指南

内容比较

注意:在学习如何使用不同的函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同的函数时,可以在上传文件时设置各自的特殊参数。其他基本步骤一致。

比较PDF内容(包括文本和图片):

  • 对于一个任务,您必须上传两个PDF文件。如果isSaveTwo设置为“1”,则处理结果将以.zip文件的形式保存,其中包含两个PDF的比较结果文件。

  • 对于同一个任务,必须上传两个PDF文件。如果isSaveTwo设置为“0”,则处理结果将以.pdf文件的形式保存,两个文件的比较结果合并到此文件中。

java
{
    "isSaveTwo": "0",
    "imgCompare": "1",
    "textCompare": "1",
    "replaceColor": "#93B9FD",
    "insertColor": "#C0FFEC",
    "deleteColor": "#FBBDBF"
}

所需参数

isSaveTwo:指定内容比较时是否生成两个输出文件:1 为是,0 为否(默认值为 0)。

imgCompare:指定是否启用图片比较:1 为是,0 为否(默认值为 1)。

textCompare:指定是否启用文本比较:1 为是,0 为否(默认值为 1)。

replaceColor:定义替换内容的颜色(默认值为 #93B9FD)。

insertColor:定义插入内容的颜色(默认值为 #C0FFEC)。

deleteColor:定义删除内容的颜色(默认值为 #FBBDBF)。

请求示例:

您需要将 apiKey 替换为您从控制台获取的 publicKey ,将 file 替换为您要转换的文件 ,language 替换为您想要的接口错误提示语言类型。

curl
curl --location --request POST 'https://api-server.compdf.com/server/v2/process/pdf/contentCompare' \
--header 'x-api-key: apiKey' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"file1"' \
--form 'file=@"file2"' \
--form 'password="" \
--form 'parameter="{ \"imgCompare\": \"1\", \"isSaveTwo\": \"0\", \"textCompare\": \"1\", \"replaceColor\": \"#FF0000\", \"insertColor\": \"#FBBDBF\", \"deleteColor\":\"#93B9FD\" }"' \
--form 'language="1"'
java
import java.io.*;
import okhttp3.*;

public class Main {
    public static void main(String[] args) throws IOException {
        File firstFile = new File("first.pdf");  
        File secondFile = new File("second.pdf");     
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("{{file}}", firstFile.getName(),
                        RequestBody.create(MediaType.parse("application/octet-stream"), 
                        firstFile)
                .addFormDataPart("{{file}}", secondFile.getName(),
                        RequestBody.create(MediaType.parse("application/octet-stream"), 
                        secondFile)
                .addFormDataPart("language", "{{language}}") 
                .addFormDataPart("password", "")
                .addFormDataPart("parameter", "{ " +
                        "\"imgCompare\": \"1\", " +
                        "\"isSaveTwo\": \"0\", " +
                        "\"textCompare\": \"1\", " +
                        "\"replaceColor\": \"#FF0000\", " +
                        "\"insertColor\": \"#FBBDBF\", " +
                        "\"deleteColor\":\"#93B9FD\" " +
                        "}")
                .build();

        Request request = new Request.Builder()
                .url("https://api-server.compdf.com/server/v2/process/pdf/contentCompare")
                .method("POST", body)
                .addHeader("x-api-key", "{{apiKey}}")
                .build();
       Response response = client.newCall(request).execute();
    }
}

结果:

文件类型文件说明
.pdf 或 .zipPDF 内容比较结果文件

叠加对比

注意:在学习不同函数的使用方法之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。

PDF文件叠加对比:

  • 在一个任务中,必须上传两个文件。
java
{
    "inTransparency": "0.5",
    "newTransparency": "0.5",
    "coverType": "0",
    "inColor": "#FBBDBF",
    "newColor": "#93B9FD"
}

所需参数

inTransparency:调整旧对比文件的透明度。(范围:0 到 1,默认值:0.5)

newTransparency:调整新对比文件的透明度。(范围:0 到 1,默认值:0.5)

coverType:设置混合模式(默认值为 0,0 代表 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:设置旧对比文件的颜色。默认值:#FBBDBF)

newColor:设置新比较文件的颜色。(默认值:#93B9FD)

请求示例:

您需要将 apiKey 替换为您从控制台获取的 publicKey ,将 file 替换为您要转换的文件 ,language 替换为您想要的接口错误提示语言类型。

curl
curl --location --request POST 'https://api-server.compdf.com/server/v2/process/pdf/coverCompare' \
--header 'x-api-key: apiKey' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"file1"' \
--form 'file=@"file2"' \
--form 'password="" \
--form 'parameter="{ \"inTransparency\":\"0.5\", \"newTransparency\":\"0.5\", \"coverType\":\"0\", \"inColor\":\"#FBBDBF\", \"newColor\":\"#93B9FD\"}"' \
--form 'language="1"'
java
import java.io.*;
import okhttp3.*;

public class Main {
    public static void main(String[] args) throws IOException {
        File firstFile = new File("first.pdf");  
        File secondFile = new File("second.pdf");     
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("{{file}}", firstFile.getName(),
                        RequestBody.create(MediaType.parse("application/octet-stream"), 
                        firstFile)
                .addFormDataPart("{{file}}", secondFile.getName(),
                        RequestBody.create(MediaType.parse("application/octet-stream"), 
                        secondFile)
                .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/v2/process/pdf/coverCompare")
                .method("POST", body)
                .addHeader("x-api-key", "{{apiKey}}")
                .build();
       Response response = client.newCall(request).execute();
    }
}

响应信息:

请求的成功响应返回 HTTP 200 OK 状态代码以及显示订单详细信息的 JSON 响应主体。

响应模式:application/json

响应参数数据类型描述
codeStringHTTP请求状态,"200"代表成功
messageString请求信息
dataObject返回结果
+taskIdString任务ID
+taskFileNumint任务处理文件数量
+taskSuccessNumint任务处理文件成功数量
+taskFailNumint任务处理文件失败数量
+taskStatusString任务状态
+assetTypeIdint使用资产类型ID
+taskCostint任务费用
+taskTimeint任务持续时间
+sourceTypeString原格式
+targetTypeString目标格式
+fileInfoDTOListArray任务文件信息
++fileKeyString文件key
++taskIdString任务ID
++fileNameString原文件名
++downFileNameString下载文件名
++fileUrlString原文件地址
++downloadUrlString处理结果文件下载地址
++sourceTypeString原格式
++targetTypeString目标格式
++fileSizeint文件大小
++convertSizeint处理结果文件大小
++convertTimeint处理消耗时间
++statusString文件处理状态
++failureCodeString文件处理失败错误码
++failureReasonString文件处理失败说明
++fileParameterString处理参数

响应示例:

json
"code": "200",
"msg": "success",
"data": {
    "taskId": "f416dbcf-0c10-4f93-ab9e-a835c1f5dba1",
    "taskFileNum": 1,
    "taskSuccessNum": 1,
    "taskFailNum": 0,
    "taskStatus": "<taskStatus>",
    "assetTypeId": 0,
    "taskCost": 1,
    "taskTime": 1,
    "sourceType": "<sourceType>",
    "targetType": "<targetType>",
    "fileInfoDTOList": [
      {
        "fileKey": "<fileKey>",
        "taskId": "<taskId>",
        "fileName": "<fileName>",
        "downFileName": "<downFileName>",
        "fileUrl": "<fileUrl>",
        "downloadUrl": "<downloadUrl>",
        "sourceType": "<sourceType>",
        "targetType": "<targetType>",
        "fileSize": 24475,
        "convertSize": 6922,
        "convertTime": 8,
        "status": "<status>",
        "failureCode": "",
        "failureReason": "",
        "fileParameter": "<fileParameter>"
      }
    ]
}

结果:

文件类型文件说明
.pdf叠加比较结果文件

异步请求

如果您需要使用文件异步处理流程,请阅读异步请求说明