Skip to content

Latest commit

 

History

History
176 lines (105 loc) · 10.2 KB

File metadata and controls

176 lines (105 loc) · 10.2 KB

ComPDF API for PHP

As part of the KDAN ecosystem, ComPDF offers powerful and reliable PDF libraries and comprehensive PDF capabilities — enabling you to build document workflows with PDF generation, PDF editing, image/PDF conversion, unstructured file parsing and data extraction, watermark, compression, comparison, and more.

ComPDF API provides a variety of PHP API tools that allow you to create an efficient document processing workflow in a single API call. Process up to free 200+ API calls per month — just sign up to get started.

If you find this library helpful, please consider giving us a ⭐ Star on GitHub! Have feedback or questions? Join the conversation in our Discussions.

Why ComPDF API?

  • Easy API Call — Complete complex PDF processing workflows with minimal code. Also supports integration with various low-code platforms, agents, MCP tools, and enterprise workflows such as Salesforce, SharePoint, Make, Zapier, ClawHub Skills, MCP.SO, and MCPMarket.

  • Comprehensive Feature Support:

    • PDF generation

    • PDF/image format conversion:Convert PDF/images to Word, Excel, PPT, HTML, RTF, images, CSV, TXT, JSON, OFD, Markdown, and searchable PDF.Convert Word, Excel, PPT, HTML, RTF, images, CSV, TXT, JSON, and Markdown to PDFs.

    • Page editing: merge, split, extract, insert, delete, and rotate PDF pages

    • Data parsing and extraction

    • Watermarking

    • PDF Compression

    • PDF comparison

  • Secure & Reliable — Enterprise-grade infrastructure with data privacy compliance.

  • Free Tier — Process up to 200+ API calls per month at no cost.

Table of Contents

Related

Requirements

Programming Environment: PHP Version 7.0 and higher.

Dependencies: Composer.

Installation

You can install the library via Composer. Run the following command.

composer require compdfkit/compdfkit-api-php

Alternatively, you can add "compdfkit/compdfkit-api-php": "^1.2.4" to your "composer.json" file and then run it.

composer update

If you are not using a PHP framework with autoload feature, you need to use the code below to autoload.

require_once('vendor/autoload.php');

Usage

Create API Client

First of all, please create an API client to complete the authentication. You need to sign in your ComPDF API account to get your publicKey and secretKey at the dashboard. If you are new to ComPDF, click here to sign up for a free trial to process 200+ API calls per month for free.

  • Project public Key: You can find the public key in the API Keys section of your ComPDF API account.

  • Project secret Key: You can find the secret Key in the API Keys section of your ComPDF API account.

    $client = new CPDFClient('public_key', 'secret_key');

Create A 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 request result, such as checking the status of the task, uploading files, starting the task, or downloading the result file.

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

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 filekey. 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.

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

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

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

Get the Task Info

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

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

Samples

There are many examples in the samples folder, which show the main features of the ComPDF API and how to use them, such as watermarking PDFs, converting PDF to Word, Excel, JPG, PNG, etc. You can copy the code to your project and run it directly. To learn more about the ComPDF API, please visit our API Reference.

Changelog

Go to our Changelog to keep up with the latest updates, improvements, and bug fixes for ComPDF API.

Support

ComPDF has a professional R&D team that produces comprehensive technical documentation and guides to help developers. Also, you can get an immediate response when reporting your problems to our support team.

  • For detailed information, please visit our guides page.
  • For technical assistance, please reach out to our technical support.
  • To get more details and an accurate quote, please contact our sales team.

Free Trial and License

The code is available as open source under the terms of the Apache-2.0 License.

ComPDF API is a powerful API that can be used to create an efficient document processing workflow in a single API call.

If you do not have a ComPDF API account, you can sign up for a free trial to process 200+ API calls per month for free.

Once you have a ComPDF API account, you can obtain your publicKey and secretKey in the dashboard.