Skip to content

Request Description

Precautions

  • The file download link returned by the interface will generally be deleted at 24 o'clock the next day. Please download and store it in time.
  • When calling the interface, please pay attention to the parameter transmission method of the corresponding interface in the document, and whether you need to carry a Token to prevent parameter confusion.
  • An HTTP status of 200 indicates that your HTTP request is successful, which does not mean that the file processes successfully.

Description of Asynchronous Task Processing

To meet the needs of users for high concurrency, the ComPDFKit API uses a message queue asynchronously to process task requests by default to ensure the high availability of the API.

Interface TypeRequest MethodResults Return MethodPros and Cons
AsynchronousAfter sending a request, there is no need to wait for the task to finish processing, and the result is obtained actively at once.Get the recognition results by querying the task result interface.When the concurrency is large, the success rate is high. When the network transmission is slow or not particularly stable, it is more stable.

Processing A PDF

Create Task

A task ID is automatically generated for you based on the type of PDF tool you choose. You can provide the callback notification URL. After the task processing is completed, we will notify you of the task result through the callback interface. You can perform other operations, according to the task result, such as downloading the result file.

Java
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF TO Word task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());

// Get a task id
String taskId = result.getTaskId();
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');

// Create a task
// Create an example of a PDF tO Word task
$taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD);
C#
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);

// Get a task id
string taskId = result.TaskId;
Python
# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a PDF tO Word task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_WORD)

# Get a task id
task_id = create_task_result.task_id
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)
        
Task { @MainActor in
    // Create a task
    let taskModel = await client.createTask(url: CPDFConversion.PDF_TO_WORD, language: .english)
    // Get a task id
    let taskId = taskModel?.taskId ?? ""
}

Parameters:

When creating a task, you can choose the language to display the error messages that are related to creating tasks. The parameter language is optional. If not set, error messages will default to English.

  • language: 1: English, 2: Chinese.

Upload Files

Upload the original file and bind the file to the task ID. The field parameter is used to pass the JSON string to set the processing parameters for the file. Each file will generate automatically a unique file key. Please note that a maximum of five files can be uploaded for a task ID and no files can be uploaded for that task after it has started.

Java
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());

// Get a task id
String taskId = result.getTaskId();

// Upload files
client.uploadFile(<convertFile>, taskId);
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');

// Create a task
// Create an example of a PDF tO Word task
$taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD);

// Upload files
$file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']);
C#
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);
// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);
// Get a task id
string taskId = result.TaskId;

// Upload files
client.UploadFile(<convertFile>, taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a PDF tO Word task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_WORD)

# Get a task id
task_id = create_task_result.task_id

# Upload files
client.upload_file(convert_file, task_id)
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)

Task { @MainActor in
    // Create a task
    // Create an example of a PDF tO Word task
    let taskModel = await client.createTask(url: CPDFConversion.PDF_TO_WORD, language: .english)
    
    // Get a task id
    let taskId = taskModel?.taskId ?? ""

    // Upload files
    let path = Bundle.main.path(forResource: "test", ofType: "pdf")
    let uploadFileModel = await client.uploadFile(filepath: path ?? "", password: "", language: .english, params: [
        CPDFFileUploadParameterKey.isContainAnnot.string() : "1",
        CPDFFileUploadParameterKey.isContainImg.string() : "1",
        CPDFFileUploadParameterKey.isFlowLayout.string() : "1"
    ], taskId: taskId)
}

Parameters:

When uploading a file, the following parameters would be needed. You can choose the language to display the error messages which are related to uploading a file. The parameter language is optional. If not set, error messages will default to English.

  • password: Enter your file password if the document is encrypted.
  • language: 1: English, 2: Chinese.

Upload Files

Execute the Task

After the file upload is completed, call this interface with the task ID to process the file.

Java
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());

// Get a task id
String taskId = result.getTaskId();

// Upload files
client.uploadFile(<convertFile>, taskId);

// Execute task
client.executeTask(taskId);
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');

// Create a task
// Create an example of a PDF tO Word task
$taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD);

// Upload files
$file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']);

// Execute task
$client->executeTask($taskInfo['taskId']);
C#
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);

// Get a task id
string taskId = result.TaskId;

// Upload files
client.UploadFile(<convertFile>, taskId);

// Execute task
client.ExecuteTask(taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a PDF tO Word task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_WORD)

# Get a task id
task_id = create_task_result.task_id

# Upload files
client.upload_file(convert_file, task_id)

# Execute task
client.execute_task(task_id)
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)

Task { @MainActor in
    // Create a task
    // Create an example of a PDF tO Word task
    let taskModel = await client.createTask(url: CPDFConversion.PDF_TO_WORD, language: .english)
    
    // Get a task id
    let taskId = taskModel?.taskId ?? ""

    // Upload files
    let path = Bundle.main.path(forResource: "test", ofType: "pdf")
    let uploadFileModel = await client.uploadFile(filepath: path ?? "", password: "", language: .english, params: [
        CPDFFileUploadParameterKey.isContainAnnot.string() : "1",
        CPDFFileUploadParameterKey.isContainImg.string() : "1",
        CPDFFileUploadParameterKey.isFlowLayout.string() : "1"
    ], taskId: taskId)

    // Execute task
    let _ = await client.processFiles(taskId: taskId, language: .english)
}

Parameters:

When executing a task, you can choose the language to display the error messages that are related to executing tasks. The parameter language is optional. If not set, error messages will default to English.

  • language: 1: English, 2: Chinese.

Get Task Information

Request task status and file-related meta data based on the task ID.

Java
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.createTask(CPDFConversionEnum.PDF_TO_WORD.getValue());

// Get a task id
String taskId = result.getTaskId();

// Upload files
client.uploadFile(<convertFile>, taskId);

// Execute task
client.executeTask(taskId);

// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.getTaskInfo(taskId);
PHP
// Create a client
$client = new CPDFClient('public_key', 'secret_key');

// Create a task
// Create an example of a PDF tO Word task
$taskInfo = $client->createTask(CPDFConversion::PDF_TO_WORD);

// Upload files
$file = $client->addFile('test.pdf')->uploadFile($taskInfo['taskId']);

// Execute task
$client->executeTask($taskInfo['taskId']);

// Query TaskInfo
$taskInfo = $client->getTaskInfo($taskInfo['taskId']);
C#
// Create a client
CPDFClient client = new CPDFClient(<publicKey>, <secretKey>);

// Create a task
// Create an example of a PDF tO Word task
CPDFCreateTaskResult result = client.CreateTask(CPDFConversionEnum.PDF_TO_WORD);

// Get a task id
string taskId = result.TaskId;

// Upload files
client.UploadFile(<convertFile>, taskId);

// Execute task
client.ExecuteTask(taskId);

// Query TaskInfo
CPDFTaskInfoResult taskInfo = client.GetTaskInfo(taskId);
Python
# Create a client
client = CPDFClient(public_key, secret_key)

# Create a task
# Create an example of a PDF tO Word task
create_task_result = client.create_task(CPDFConversionEnum.PDF_TO_WORD)

# Get a task id
task_id = create_task_result.task_id

# Upload files
client.upload_file(convert_file, task_id)

# Execute task
client.execute_task(task_id)

# Query TaskInfo
task_info = client.get_task_info(task_id)
Swift
// Create a client
let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)

Task { @MainActor in
    // Create a task
    // Create an example of a PDF tO Word task
    let taskModel = await client.createTask(url: CPDFConversion.PDF_TO_WORD, language: .english)
    
    // Get a task id
    let taskId = taskModel?.taskId ?? ""

    // Upload files
    let path = Bundle.main.path(forResource: "test", ofType: "pdf")
    let uploadFileModel = await client.uploadFile(filepath: path ?? "", password: "", language: .english, params: [
        CPDFFileUploadParameterKey.isContainAnnot.string() : "1",
        CPDFFileUploadParameterKey.isContainImg.string() : "1",
        CPDFFileUploadParameterKey.isFlowLayout.string() : "1"
    ], taskId: taskId)

    // Execute task
    let _ = await client.processFiles(taskId: taskId, language: .english)
    // Query TaskInfo
    let taskInfoModel = await client.getTaskInfo(taskId: taskId, language: .english)
}

Parameters:

When querying task information, you can choose the language to display the error messages that are related to querying task information. The parameter language is optional. If not set, error messages will default to English.

  • language: 1: English, 2: Chinese.