Skip to content
ComPDF

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:

java
{
  "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
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"'
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("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 parameterData typeDescription
codeStringHTTP request status; "200" means success
messageStringRequest message
dataObjectReturned result
+taskIdStringTask ID
+taskFileNumintNumber of processed files
+taskSuccessNumintNumber of successful files
+taskFailNumintNumber of failed files
+taskStatusStringTask status
+assetTypeIdintAsset type ID used
+taskCostintTask cost
+taskTimeintTask duration
+sourceTypeStringSource format
+targetTypeStringTarget format
+fileInfoDTOListArrayTask file information
++fileKeyStringFile key
++taskIdStringTask ID
++fileNameStringSource file name
++downFileNameStringDownload file name
++fileUrlStringSource file URL
++downloadUrlStringFile download URL for the result
++sourceTypeStringSource format
++targetTypeStringTarget format
++fileSizeintFile size
++convertSizeintResult file size
++convertTimeintProcessing time
++statusStringFile processing status
++failureCodeStringFailure error code for file processing
++failureReasonStringFailure description
++fileParameterStringProcessing parameters

Response example:

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>"
      }
    ]
}

Result:

File typeDescription
.pdfGenerated PDF file

Asynchronous request

If you need to use the asynchronous file processing flow, read Asynchronous Request Guide.