0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Combine PDF Files with PDF API

Posted at

See more on “How to Combine PDF Files Mac” and Combine PDF Without Adobe.

1. Register and authentication

You can register a free ComPDFKit API account, which allows you to process more than 1,000 documents for free and unlimited within 30 days.
ComPDFKit API uses the JSON Web Tokens method for secure authentication. Get your Public Key and Secret Key from the control panel and authenticate it as follows.

// Create a client let client: CPDFClient = CPDFClient(publicKey: public_key, secretKey: secret_key)

2. Create PDF merge tasks

Select the PDF merge tool and replace it with the accessToken obtained in the previous step. Replace the display language of the error message with the language type you want. Then you can get the taskId in the response data.

// Create a task // Create an example of a PDF merge task let taskModel = await client.createTask(url: CPDFDocumentEditor.MERGE, language: .english) // Get a task id let taskId = taskModel?.taskId ?? ""

3. Upload files

Upload the PDF files you want to merge and bind them with the task ID.

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

Note:
In the same task, upload multiple files (up to five). If pageOptions is not passed, it will be a multi-file merge.
In the same task, upload multiple files (up to five) and pageOptions, and merge the specified page numbers of multiple files.
The upload interface supports single-file uploads only.

4. Merge PDF files

After the file upload is completed, call this interface through the task ID to merge the files.

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

5. Get task information

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

// 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 merge task let taskModel = await client.createTask(url: CPDFDocumentEditor.MERGE, 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 ?? "", language: .english, params: [CPDFFileUploadParameterKey.pageOptions.string():["1,2"]], taskId: taskId) // Upload files let uploadFileModel2 = await client.uploadFile(filepath: path ?? "",language: .english ,params: [CPDFFileUploadParameterKey.pageOptions.string():["1,2"]], taskId: taskId) // Execute task let _ = await client.processFiles(taskId: taskId, language: .english) // Query TaskInfo let taskInfoModel = await client.getTaskInfo(taskId: taskId, language: .english) }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?