ComPDFKit API Reference v0.2.0.md 24 KB

1. Overview

1.1 Introduction

Welcome to the ComPDFKit API documentation! The ComPDFKit API is organized around the REST standard and provides you with a simple document-upload, document-process, document-download workflow. You can choose extended functions according to your needs, such as converting documents in PDF format to Office format or image format, and more.

Before you begin, register to ComPDFKit API Developers and you will be provided with a free account. This account can process 100 files for free within a 30-day validity period. If you need more, please contact us: support@compdf.com

1.2 Function

The ComPDFKit-SaaS API provides a variety of operation APIs to support processing the following file format conversions:

  • PDF to Office
function file format
PDF to Word pdf/docx
PDF to PPT pdf/pptx
PDF to Excel pdf/xlsx
  • Office to PDF
function file format
Word to PDF doc/pdf docx/pdf
Excel to PDF xls/pdf xlsx/pdf
PPT to PDF ppt/pdf pptx/pdf
  • Other formats
function file format
TXT to PDF txt/pdf
PNG to PDF png/pdf
PDF to TXT pdf/txt
PDF to picture pdf/png pdf/jpg

ComPDFKit-SaaS API will automatically detect the type of uploaded file - you don't have to modify the file extension.

2. Quick Start

2.1 Supported languages

ComPDFKit SaaS API supports all languages that allow making HTTP requests, including but not limited to Java, JavaScript, C#.

2.2 Preparation

Before you begin, you may need to do some preparatory work.

  • Contact us to become a developer (email: support@compdf.com ).
  • Obtain the project ID and its related key from the API Keys section of the console.
  • Finally, remember to read this document!

2.3 Authentication

2.3.1 Request an access token

You can request an access token and related authentication information by sending your username and password,This token must be carried in header request parameter when you call subsequent interfaces:Authorization: Bearer {signed_token}.

Request method

  • request method: POST
  • parameter transfer method: Body (json)

Request parameter

parameter name data type description required
publicKey String Project public Key You can find the public key in Management Panel. yes
secretKey String Project secret Key You can find the secret Key in Management Panel. yes

Request address

https://api-cn-east-1.17pdf.com/server/v1/oauth/token

Return parameter

parameter name data type description
accessToken String Token
tokenType String Token type
expiresIn String Token validity
scope String Token Range
projectName String Project Name
"code": "200",
"msg": "success",
"data": {
    "accessToken": "256e78bc-982f-421e-be87-df268a683b14",
    "tokenType": "bearer",
    "expiresIn": "41767",
    "scope": "server",
    "projectName": "Test"
}

2.4 Request Workflow

The processing workflow of the ComPDFKit API is very simple. It consists of four basic request instructions: create a task, upload a file, execute a task, and download a result file. Through these four requests, you can select the corresponding PDF tool to process your file and obtain the download link of the result file.

英文副本-API业务流程图

In the Developer's Guide - Start (3.2), you will see the detailed explanation and reference of the four requests and step parameters.

3. Developer's Guide

3.1 Pre-preparation

To start developing, you need to request the server address and all file tool types currently supported, and then select the corresponding function according to your needs.

3.1.1 Request server list

This interface is used to obtain the server list. You can retrieve the server region and server address.

Request method

  • request method: GET
  • parameter transfer method: Query

Request address

https://api-cn-east-1.17pdf.com/server/v1/server/all

Return parameter

parameter name data type description
serverName String server location
serverUrl String server address url
"code": "200",
"msg": "success",
"data": {
    "serverName": "zh_CN",
    "serverUrl": "api-cn-east-1.17pdf.com"
}

3.1.2 Request PDF tool list

This interface is used to obtain the collection of all PDF tools supported by the ComPDFKit API, and you can query the URL of each PDF tool.

Request method

  • request method: GET
  • parameter transfer method: Query

Request address

https://api-cn-east-1.17pdf.com/server/v1/tool/support

Return parameter

parameter name data type description
sourceTypeName String Source file format
targetTypeName String Destination file format
executeTypeUrl String Type of execution task
"code": "200",
"msg": "success",
"data": {
    {
        "sourceTypeName": "pdf",
        "targetTypeName": "docx",
        "executeTypeUrl": "pdf/docx"
    },
    {
        "sourceTypeName": "pdf",
        "targetTypeName": "jpg",
        "executeTypeUrl": "pdf/jpg"
    },
    {
        "sourceTypeName": "doc",
        "targetTypeName": "pdf",
        "executeTypeUrl": "doc/pdf"
    }
    ......
}

3.2 Start

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

Request method

  • request method: GET
  • parameter transfer method: Query

Request method

parameter name data type description required
executeTypeUrl String Type of execution task yes

Request address

https://api-cn-east-1.17pdf.com/server/v1/task/{executeTypeUrl}

Return parameter

parameter name data type description
taskId String task id
"code": "200",
"msg": "success",
"data": {
    "taskId": "2da9dc86-5f41-4991-b9da-bc8434f64cc5"
}

3.2.2 Upload file

Upload the original file and bind the file to the task ID. Each file will generate automatically a unique filekey.

Request method

  • request method: POST
  • parameter transfer method: Body (form-data)

Request parameter

parameter name data type description required
file File uploaded file yes
taskId String task id yes
password String password no

Request address

https://api-cn-east-1.17pdf.com/server/v1/file/upload

Return parameter

parameter name data type description
fileKey String file unique identification
fileUrl String file storage path
"code": "200",
"msg": "success",
"data": {
    "fileKey": "c6e0dcde-7533-4058-81fb-ea2a26677f85",
    "fileUrl": "https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/***.pdf"
}

3.2.3 Perform tasks

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

Request method

  • request method: GET
  • parameter transfer method: Query

Request parameter

parameter name data type description required
taskId String task id yes

Request address

https://api-cn-east-1.17pdf.com/server/v1/execute/start?taskId='135e8570-6377-4660-94d2-867952796f2c'

Return parameter

parameter name data type description
taskId String task id
"code": "200",
"msg": "success",
"data": {
    "taskId": "135e8570-6377-4660-94d2-867952796f2c"
}

3.2.4 Download files

Get the download link of the corresponding result file according to the filekey of each file.

Request method

  • request method: GET
  • parameter transfer method: Query

Request parameter

parameter name data type description required
fileKey String file unique identification yes

Request address

https://api-cn-east-1.17pdf.com/server/v1/file/fileInfo?fileKey='c6e0dcde-7533-4058-81fb-ea2a26677f85'

Return parameter

parameter name data type description
fileKey String file unique identification
taskId String task id
fileName String original file name
downFileName String down File Name
fileUrl String original file address
downloadUrl String transfer download address
sourceType String source file format
targetType String target file format
fileSize Long file size
convertSize Long convert success size
convertTime Long conversion time
status String File Conversion Status
failureCode String failure reason code
failureReason String failure reason
"code": "200",
"msg": "success",
"data": {
    "fileKey": "ba13a2a8-1278-43d4-a9a6-7ecc28a0804f",
    "taskId": "f416dbcf-0c10-4f93-ab9e-a835c1f5dba1",
    "fileName": "test.pdf",
    "downFileName": "test.docx",
    "fileUrl": "https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/test.pdf",
    "downloadUrl": "https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/test.docx",
    "sourceType": "pdf",
    "targetType": "docx",
    "fileSize": 24475,
    "convertSize": 6922,
    "convertTime": 8,
    "status": "success",
    "failureCode": "",
    "failureReason": ""
}

Note:

status :File Conversion Status

status description
created File upload succeeded
processing File conversion in progress
success File conversion succeeded
failed File conversion failed
overdue File saving expired, file deletion

3.3 System resource

3.3.1 Get task information

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

Request method

  • request method: GET
  • parameter transfer method: Query

Request parameter

parameter name data type description required
taskId String task id yes

Request address

https://api-cn-east-1.17pdf.com/server/v1/task/taskInfo?taskId='135e8570-6377-4660-94d2-867952796f2c'

Return parameter

return parameter data type description
taskId String task id
taskFileNum Integer number of task files
taskSuccessNum String number of successes
taskFailNum String number of failures
taskStatus String task status
assetTypeId String Use Asset Type
taskCost String task cost
taskTime Long task duration
sourceType Long source file format
targetType Long target file format
fileInfoDTOList List task file information
"code": "200",
"msg": "success",
"data": {
    "taskId": "f416dbcf-0c10-4f93-ab9e-a835c1f5dba1",
    "taskFileNum": 1,
    "taskSuccessNum": 1,
    "taskFailNum": 0,
    "taskStatus": "TaskFinish",
    "assetTypeId": 0,
    "taskCost": 1,
    "taskTime": 1,
    "sourceType": "pdf",
    "targetType": "docx",
    "fileInfoDTOList": [
      {
        "fileKey": "ba13a2a8-1278-43d4-a9a6-7ecc28a0804f",
        "taskId": "f416dbcf-0c10-4f93-ab9e-a835c1f5dba1",
        "fileName": "test.pdf",
        "downFileName": "test.docx",
        "fileUrl": "https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/test.pdf",
        "downloadUrl": "https://pdfreader-dev.oss-cn-shanghai.aliyuncs.com/test.docx",
        "sourceType": "pdf",
        "targetType": "docx",
        "fileSize": 24475,
        "convertSize": 6922,
        "convertTime": 8,
        "status": "success",
        "failureCode": "",
        "failureReason": ""
      }
    ]
}

Note:

taskStatus :Task processing status

status description
TaskStart Task created successfully
TaskWaiting Task waiting for processing
TaskProcessing The task is being processed
TaskFinish Task processing completed
TaskOverdue Task waiting for processing timeout

3.3.2 Get asset details

Get the remaining assets of the current user.

Request method

  • request method:GET
  • parameter transfer mode:Query

Request address

https://api-cn-east-1.17pdf.com/server/v1/asset/info

Return parameter

return parameter data type description
tenantAsset List asset Information
assetTypeName String asset Type
asset Integer asset balance
withholdingAsset Integer total withholding assets
"code": "200",
"msg": "success",
"data": {
    "tenantAsset": [
      {
        "assetTypeName": "SUBSCRIPTIONS",
        "asset": 12,
        "withholdingAsset": 0
      },
      {
        "assetTypeName": "PACKAGES",
        "asset": 1,
        "withholdingAsset": 0
      }
    ]
}

3.3.3 Request the current user file transfer task list

Request the current user file transfer task list.

Request method

  • request method:GET
  • parameter transfer mode:Query

Request parameter

  • page:Pagination - current number of pages, not required, default to 1 if not filled
  • size:Pagination - the number of items displayed on the page, not required, the default is 10 if not filled
parameter name data type description required
page Long current page no(If not filled, the default is 1)
size Long number of pages no(If not filled, the default is 10)

Request address

https://api-cn-east-1.17pdf.com/server/v1/task/list

Return parameter

return parameter data type description
createdBy String founder
updatedBy String updater
creationTime LocalDateTime creation time
updateTime LocalDateTime update time
id Long task primary key id
taskId String task id
taskUrl taskUrl task original folder
taskLoadUrl String task conversion folder
taskFileNum Integer number of task files
taskSuccessNum Integer number of successes
taskFailNum Integer number of failures
taskStatus String task status
assetTypeId Integer working with asset types
taskCost Integer task cost
taskTime Long task duration
callbackUrl String callback address
server String server address
sourceType String source file format
targetType String target file format
tenantId Long tenant id
{
    "records": [
      {
        "createdBy": null,
        "updatedBy": null,
        "creationTime": "2022-08-31 15:06:20",
        "updateTime": "2022-08-31 15:14:44",
        "id": 771751854513061888,
        "taskId": "a300c232-0a2d-4e3c-95f2-cfb4604b2018",
        "taskUrl": "",
        "taskLoadUrl": "",
        "taskFileNum": 3,
        "taskSuccessNum": 0,
        "taskFailNum": 0,
        "taskStatus": "TaskFinish",
        "assetTypeId": 0,
        "taskCost": 3,
        "taskTime": 0,
        "callbackUrl": "",
        "server": "",
        "sourceType": "pdf",
        "targetType": "docx",
        "tenantId": 1
      },
      {
        "createdBy": null,
        "updatedBy": null,
        "creationTime": "2022-08-31 15:25:24",
        "updateTime": "2022-08-31 15:26:17",
        "id": 771756653954465793,
        "taskId": "e74d60a6-fbd3-4d7d-9efa-0dc70297ee0b",
        "taskUrl": "",
        "taskLoadUrl": "",
        "taskFileNum": 3,
        "taskSuccessNum": 3,
        "taskFailNum": 0,
        "taskStatus": "TaskFinish",
        "assetTypeId": 0,
        "taskCost": 3,
        "taskTime": 3,
        "callbackUrl": "",
        "server": "",
        "sourceType": "pdf",
        "targetType": "docx",
        "tenantId": 1
      }
    ],
    "total": 528,
    "size": 2,
    "current": 1,
    "orders": [],
    "optimizeCountSql": true,
    "searchCount": true,
    "countId": null,
    "maxLimit": null,
    "pages": 264
}

3.4 Return error code

code describe
01001 System internal exception
01002 Server file upload exception after file conversion
01003 User file upload exception
01004 File download exception
01005 File cannot be empty
01201 File conversion failed: system memory problem
01202 File conversion failed:unknown mistake
01203 File conversion failed:file not found or cannot be opened
01204 File conversion failed:unsupported security mechanism
01205 File conversion failed:unknown mistake
02001 File format error
02002 File conversion format not supported
02201 File conversion failed:file is encrypted
02203 File conversion failed:abnormal PDF file
02204 File conversion failed:file format error, not PDF
02205 File conversion failed:The file is encrypted and protected
02206 File conversion failed: The content of the file is wrong or the page is missing
02207 File conversion failed:The file class is incorrect or the file is encrypted and protected
02208 File conversion failed:error initializing ExcelXml
02209 File conversion failed:transfer timed out, please do not upload too large files
02210 File conversion failed

4. Webhook

4.1 Events

ComPDFKit API can notify your application about the status of tasks. You cancreate and manage your webhooks on the ComPDFKit API dashboard.

4.1.1 Available webhook events

event name event description
task.start The task is created successfully. The current event will be triggered when each new task is created successfully
task.finish When the task processing is completed, all files under the task are processed, triggering the current event (regardless of whether the file processing is successful or not)
task.overdue The task waiting for processing has timed out. The task has not been executed since it was created. The current event is triggered when a certain threshold (one hour) is reached
file.start The current event is triggered when the file is uploaded successfully
file.success The file is processed successfully. The current event is triggered when the file is processed successfully
file.failed File processing failed. The current event is triggered when file processing fails

4.2 Signing

Our request is encrypted and signed. If you receive a Webhook, you should verify it to ensure that it comes from us. Each Webhook has a unique signature key. You can use this button to display the signing key in Webhook Settings.

4.3 Example of Webhook request

4.3.1 Request mode

POST https://your-webhook

4.3.2 Headers

Content-Type: application/json
ComPDFKit-Signature: 8fef357511abec47a4a22313c1dcdb8b

4.3.3 Example Payload

Request parameters

parameter name data type description
eventName String Current event type
webhookToken String ComPDFKit-Signature
sendTime Date Sending time
eventObject String Trigger object of the current event
{
    "eventName": "task.finish",
    "webhookToken": "225c4d7461bb91133a91251cece9cce2",
    "sendTime": Thu Dec 15 14:45:47 GMT+08:00 2022,
    "eventObject": "e74d60a6-fbd3-4d7d-9efa-0dc70297ee0b"
}

Note:

eventObject

  • If the current event type is a task object, the eventObject is a taskId
  • If the current event type is a file object, the eventObject is a fileKey

5. Support

5.1 Report a problem

Thanks for your interest in the ComPDFKit API! The ComPDFKit API provides an excellent set of document processing tools, enabling your developers to easily integrate PDF rendering capabilities into your applications, providing your users with an efficient and high-quality document experience. If you encounter any technical questions or bug issues when using ComPDFKit for Windows, please submit the problem report to the ComPDFKit team. More information as follows would help us to solve your problem:

  • The version of the ComPDFKit API you are currently using.
  • Your operating system and IDE version.
  • Detailed description of the problem.
  • Any other related information, such as screenshots of errors.

5.2 Contact us

Official website homepage:

https://www.compdf.com

User Support Contact:

Email Address: support@compdf.com

thanks,

ComPDFKit Team