Image to PDF Guide
Note: Before using the different functions, we recommend reading Request Workflow to understand the basic PDF processing flow. When using different functions, you can set each tool's special parameters when uploading files. The rest of the steps are the same.
Image to PDF:
{
"enableOcr": 0,
"ocrRecognitionLang": "AUTO"
}Required parameters
enableOcr: Whether to use OCR (0: disabled; 1: enabled). Default: 0.
ocrRecognitionLang: OCR recognition language. Supported values:
AUTO: Auto, CHINESE: Simplified Chinese, CHINESE_TRAD: Traditional Chinese, ENGLISH: English, KOREAN: Korean, JAPANESE: Japanese, LATIN: Latin, DEVANAGARI: Devanagari, CYRILLIC: Cyrillic, ARABIC: Arabic, TAMIL: Tamil, TELUGU: Telugu, KANNADA: Kannada, THAI: Thai, GREEK: Greek, ESLAV: Eslav language family. Default: AUTO.
Request example:
Replace apiKey with the publicKey from the console, file with the file you want to convert, and language with the error message language you want.
curl --location --request POST 'https://api-server.compdf.com/server/v2/process/img/pdf' \
--header 'x-api-key: apiKey' \
--header 'Accept: */*' \
--header 'Connection: keep-alive' \
--header 'Content-Type: multipart/form-data' \
--form 'file=@"file"' \
--form 'parameter="{ \"enableOcr\": 0, \"ocrRecognitionLang\": \"ENGLISH\" }"' \
--form 'language="1"'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("language","{{language}}")
.addFormDataPart("parameter","{ \"enableOcr\": 1 }")
.build();
Request request = new Request.Builder()
.url("https://api-server.compdf.com/server/v2/process/img/pdf")
.method("POST", body)
.addHeader("x-api-key", "{{apiKey}}")
.build();
Response response = client.newCall(request).execute();
}
}Response information:
A successful response returns HTTP 200 OK and a JSON response body with the task details.
Response mode: application/json
| Response parameter | Data type | Description |
|---|---|---|
| code | String | HTTP request status; "200" means success |
| message | String | Request message |
| data | Object | Returned result |
| +taskId | String | Task ID |
| +taskFileNum | int | Number of processed files |
| +taskSuccessNum | int | Number of successful files |
| +taskFailNum | int | Number of failed files |
| +taskStatus | String | Task status |
| +assetTypeId | int | Asset type ID used |
| +taskCost | int | Task cost |
| +taskTime | int | Task duration |
| +sourceType | String | Source format |
| +targetType | String | Target format |
| +fileInfoDTOList | Array | Task file information |
| ++fileKey | String | File key |
| ++taskId | String | Task ID |
| ++fileName | String | Source file name |
| ++downFileName | String | Download file name |
| ++fileUrl | String | Source file URL |
| ++downloadUrl | String | File download URL for the result |
| ++sourceType | String | Source format |
| ++targetType | String | Target format |
| ++fileSize | int | File size |
| ++convertSize | int | Result file size |
| ++convertTime | int | Processing time |
| ++status | String | File processing status |
| ++failureCode | String | Failure error code for file processing |
| ++failureReason | String | Failure description |
| ++fileParameter | String | Processing parameters |
Response example:
"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>"
}
]
}Result:
| File type | Description |
|---|---|
| Generated PDF file |
Asynchronous request
If you need to use the asynchronous file processing flow, read Asynchronous Request Guide.