比较文档
内容比较
注意:在学习如何使用不同的函数之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同的函数时,可以在上传文件时设置各自的特殊参数。其他基本步骤一致。
比较PDF内容(包括文本和图片):
对于一个任务,您必须上传两个PDF文件。如果
isSaveTwo
设置为“1”,则处理结果将以.zip文件的形式保存,其中包含两个PDF的比较结果文件。对于同一个任务,必须上传两个PDF文件。如果
isSaveTwo
设置为“0”,则处理结果将以.pdf文件的形式保存,两个文件的比较结果合并到此文件中。
{
"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)。
示例
授权
您需要将认证响应中的 和 替换为从控制台获取的 publicKey 和 secretKey,并使用 accessToken。
curlcurl --location --request POST 'https://api-server.compdf.com/server/v1/oauth/token' \ --header 'Content-Type: application/json' \ --data-raw '{ "publicKey": "publicKey", "secretKey": "secretKey" }'
javaimport 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(); } }
创建任务
您需要将 替换为上一步获取的 accessToken,将 ***替换为所需的界面和任务错误消息语言类型。请求成功后,您将从响应中收到 taskId。
curlcurl --location --request GET 'https://api-server.compdf.com/server/v1/task/pdf/contentCompare' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
上传文件
将 替换为您要转换的文件,将 替换为您上一步获取到的 taskId,将 替换为您需要的界面错误信息语言类型,将 替换为您第一步获取到的 accessToken。
curlcurl --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\"}"'
javaimport 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(); } }
执行任务
将 替换为 创建任务 步骤中获取的 taskId,将 替换为第一步获取的 access_token,将 替换为所需的界面错误信息语言类型。
curlcurl --location -g --request GET 'https://api-server.compdf.com/server/v1/execute/start?taskId=taskId' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
获取任务信息
将 替换为 创建任务 步骤中获取的 taskId,将 替换为第一步中获取的 access_token。
curlcurl --location -g --request GET 'https://api-server.compdf.com/server/v1/task/taskInfo?taskId=taskId' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
结果
文件类型 | 文件说明 |
---|---|
.pdf 或 .zip | PDF 内容比较结果文件 |
叠加对比
注意:在学习不同函数的使用方法之前,建议先阅读请求描述,了解基本的PDF处理流程。使用不同函数时,可以在上传文件时设置各自特殊的参数。其他基本步骤一致。
PDF文件叠加对比:
- 在一个任务中,必须上传两个文件。
{
"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)
示例
授权
您需要将认证响应中的 和 替换为从控制台获取的 publicKey 和 secretKey,并使用 accessToken。
curlcurl --location --request POST 'https://api-server.compdf.com/server/v1/oauth/token' \ --header 'Content-Type: application/json' \ --data-raw '{ "publicKey": "publicKey", "secretKey": "secretKey" }'
javaimport 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(); } }
创建任务
您需要将 替换为上一步获取的 accessToken,将 ***替换为所需的界面和任务错误消息语言类型。请求成功后,您将从响应中收到 taskId。
curlcurl --location --request GET 'https://api-server.compdf.com/server/v1/task/pdf/coverCompare' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
上传文件
将 替换为您要转换的文件,将 替换为您上一步获取到的 taskId,将 替换为您需要的界面错误信息语言类型,将 替换为您第一步获取到的 accessToken。
curlcurl --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\"}"'
javaimport 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(); } }
执行任务
将 替换为 创建任务 步骤中获取的 taskId,将 替换为第一步获取的 access_token,将 替换为所需的界面错误信息语言类型。
curlcurl --location -g --request GET 'https://api-server.compdf.com/server/v1/execute/start?taskId=taskId' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
获取任务信息
将 替换为 创建任务 步骤中获取的 taskId,将 替换为第一步中获取的 access_token。
curlcurl --location -g --request GET 'https://api-server.compdf.com/server/v1/task/taskInfo?taskId=taskId' \ --header 'Authorization: Bearer accessToken'
javaimport 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(); } }
结果:
文件类型 | 文件说明 |
---|---|
叠加比较结果文件 |