Skip to content

API for All Features

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 need to set their own special parameters when uploading files. Other basic steps are consistent.

Convert from PDF

PDF To Word

With the PDF to Word tool, you can convert your PDF file into a Word file. The following examples show how to upload a test PDF file and convert it into a Word file (.docx) using Java, PHP, C#, Python, and Swift languages.

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);

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

// File handling parameter settings
CPDFToWordParameter fileParameter = new CPDFToWordParameter();
fileParameter.setIsContainAnnot("1");
fileParameter.setIsContainImg("1");
fileParameter.setIsFlowLayout("1");

// Upload files
client.uploadFile(new File("test.pdf"), taskId, fileParameter);

// 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);

// File handling parameter settings
$file = $client->addFile('test.pdf')
    ->setIsContainAnnot('1')
    ->setIsContainImg('1')
    ->setIsFlowLayout('1');

// Upload files
$fileInfo = $file->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;

// File handling parameter settings
CPDFToWordParameter fileParameter = new CPDFToWordParameter();
fileParameter.IsContainAnnot = "1";
fileParameter.IsContainImg = "1";
fileParameter.IsFlowLayout = "1";

// Upload files
client.UploadFile(new FileInfo("test.pdf"), taskId, fileParameter);

// 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

# File handling parameter settings
file_parameter = CPDFToWordParameter()
file_parameter.is_contain_annot = CPDFToWordParameter.IS_CONTAIN_ANNOT
file_parameter.is_contain_img = CPDFToWordParameter.IS_CONTAIN_IMG
file_parameter.is_flow_layout = CPDFToWordParameter.IS_FLOW_LAYOUT

# Upload files
client.upload_file('test.pdf', task_id, file_parameter)

# 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)
}

Needed Parameters:

  • isFlowLayout: Typesetting method (1: flow layout, 0: box layout) Default box layout.
  • isContainImg: Whether to include pictures (1: yes, 0: no).
  • isContainAnnot: Whether to include comments (1: Yes, 0: No).

Result:

File TypeDescription
.docxThe Word file after the transfer process is completed.