Intelligent Document Parsing
Output .Json format file
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.
Intelligent Text Extraction:
{
"version": "v2"
}
Needed Parameters
version
: PDF to JSON different versions (v1, v2), use guide document parsing when v2 is selected. Default v1.
Example
Authentication
You need to replace and with accessToken in the publicKey and secretKey authentication getback values you get from the console.
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(); } }
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.
curlcurl --location --request GET 'https://api-server.compdf.com/server/v1/task/pdf/json' \ --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/json?language={{language}}") .method("GET", body) .addHeader("Authorization", "Bearer {{accessToken}}") .build(); Response response = client.newCall(request).execute(); } }
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.
-Supported image formats: jpg,jpeg,png,bmp
curlcurl --location --request POST 'https://api-server.compdf.com/server/v1/file/upload' \ --header 'Authorization: Bearer accessToken' \ --form 'file=@"test.png"' \ --form 'taskId="taskId"' \ --form 'password=""' \ --form 'parameter="{ \"lang\": \"auto\" }"' \
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("parameter","{ \"lang\": \"auto\" }") .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(); } }
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.
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(); } }
Get Task Information
Replace with you from Create the task obtained in the taskId, replaced by access_token obtained in the first step.
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(); } }
Result
File Type | Description |
---|---|
.Zip | The zip includes Json result files and image folders. |
Content
Parameter | Description |
---|---|
rect | The position of the object on the page |
page | The page number where the object is located |
order_index | The reading order position of the object on the current page |
type | Used to identify the type of the object. Currently supported object types are: Text: Ordinary text type object, containing text content. Image: Image type object, containing the path of the image. Table and UnstdTable: Table type object, containing the content and structure of the table. Catalogue: Catalogue type object, containing the content of the catalogue List and UnorderedList: List type object, containing the content of the list Formula: Formula type object, containing the content of the formula Header: Header type object, containing the content of the header Footer: Footer type object, containing the content of the footer PageNumber: Page number type object, containing the content of the page number FigureTitle: Figure title type object, containing the content of the figure title FigureCaption: Figure caption type object, containing the content of the figure caption |
{
"version": "1.0.0",
"objects": [
{
"type": "Header",
"rect": [
49.0,
43.5,
171.5,
76.0
],
"text": "Intelligent Document Parsing",
"page": 0,
"order_index": 0
}
]
}