跳到主要内容

API文档

通过REST API将PDF分析集成到您的应用程序中

快速入门

1

创建账户

注册免费的PDFCheck账户即可开始使用。

2

生成API令牌

前往API令牌页面并创建新令牌。

3

发送第一个请求

使用令牌对API请求进行身份验证。

身份验证

所有API请求都需要在Authorization头中使用Bearer令牌进行身份验证。

Authorization: Bearer YOUR_API_TOKEN

基础URL

https://pdf.businesspress.io/api/v1

速率限制

免费账户每天限制50次PDF分析。每个API响应中包含剩余次数。

端点

GET /user

获取已验证用户的信息,包括每日使用限额。

响应示例

{
  "success": true,
  "data": {
    "name": "John Doe",
    "email": "john@example.com",
    "daily_limit": 50,
    "remaining_checks": 47,
    "checks_used_today": 3
  }
}
POST /pdf/analyze

上传并分析PDF文件。返回从PDF中提取的详细元数据。

请求体

名称 类型 必填 描述
file file 必填 要分析的PDF文件(最大100MB)

请求示例

curl -X POST https://pdf.businesspress.io/api/v1/pdf/analyze \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -F "file=@document.pdf"

响应示例

{
  "success": true,
  "data": {
    "id": "abc123xyz789",
    "filename": "document.pdf",
    "file_size": 1048576,
    "file_size_formatted": "1.00 MB",
    "metadata": {
      "title": "My Document",
      "author": "John Doe",
      "creator": "Microsoft Word",
      "producer": "Adobe PDF Library",
      "page_count": 10,
      "pdf_version": "1.7",
      "dates": {
        "created": "2025-01-15T10:30:00Z",
        "modified": "2025-01-16T14:22:00Z",
        "was_modified": true
      }
    },
    "analyzed_at": "2025-01-17T18:00:00Z"
  },
  "remaining_checks": 46
}
GET /pdf

列出已验证用户的所有PDF分析记录,支持分页。

查询参数

名称 类型 默认值 描述
per_page integer 20 每页结果数(1-100)

响应示例

{
  "success": true,
  "data": [
    {
      "id": "abc123xyz789",
      "filename": "document.pdf",
      "file_size": 1048576,
      "file_size_formatted": "1.00 MB",
      "analyzed_at": "2025-01-17T18:00:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "last_page": 1,
    "per_page": 20,
    "total": 1
  }
}
GET /pdf/{id}

通过分析ID(共享令牌)获取详细的分析结果。

请求示例

curl https://pdf.businesspress.io/api/v1/pdf/abc123xyz789 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

令牌管理

GET /tokens

列出已验证用户的所有API令牌。

POST /tokens

创建新的API令牌。令牌仅在响应中显示一次。

请求体

名称 类型 必填 描述
name string 必填 令牌的描述性名称
DELETE /tokens/{id}

永久撤销(删除)API令牌。

错误代码

HTTP代码 错误代码 描述
401 unauthenticated 无效或缺少API令牌
404 not_found 资源未找到或访问被拒绝
422 analysis_failed PDF无法处理(文件无效或损坏)
429 daily_limit_exceeded 已超出每日限额,请明天再试

代码示例

cURL

# Analyze a PDF
curl -X POST https://pdf.businesspress.io/api/v1/pdf/analyze \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -F "file=@/path/to/document.pdf"

# Get analysis result
curl https://pdf.businesspress.io/api/v1/pdf/abc123xyz789 \
  -H "Authorization: Bearer YOUR_API_TOKEN"

# List all analyses
curl https://pdf.businesspress.io/api/v1/pdf \
  -H "Authorization: Bearer YOUR_API_TOKEN"

PHP

<?php
$apiToken = 'YOUR_API_TOKEN';
$filePath = '/path/to/document.pdf';

// Analyze PDF
$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://pdf.businesspress.io/api/v1/pdf/analyze',
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiToken,
    ],
    CURLOPT_POSTFIELDS => [
        'file' => new CURLFile($filePath, 'application/pdf'),
    ],
]);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['success']) {
    echo "Analysis ID: " . $result['data']['id'] . "\n";
    echo "Pages: " . $result['data']['metadata']['page_count'] . "\n";
    echo "Remaining checks: " . $result['remaining_checks'] . "\n";
}

curl_close($ch);

Python

import requests

API_TOKEN = 'YOUR_API_TOKEN'
BASE_URL = 'https://pdf.businesspress.io/api/v1'

headers = {
    'Authorization': f'Bearer {API_TOKEN}'
}

# Analyze PDF
with open('/path/to/document.pdf', 'rb') as f:
    response = requests.post(
        f'{BASE_URL}/pdf/analyze',
        headers=headers,
        files={'file': ('document.pdf', f, 'application/pdf')}
    )

result = response.json()

if result['success']:
    print(f"Analysis ID: {result['data']['id']}")
    print(f"Pages: {result['data']['metadata']['page_count']}")
    print(f"Remaining checks: {result['remaining_checks']}")

# Get analysis by ID
response = requests.get(
    f"{BASE_URL}/pdf/{result['data']['id']}",
    headers=headers
)
print(response.json())

JavaScript (Node.js)

const fs = require('fs');
const FormData = require('form-data');

const API_TOKEN = 'YOUR_API_TOKEN';
const BASE_URL = 'https://pdf.businesspress.io/api/v1';

async function analyzePdf(filePath) {
    const form = new FormData();
    form.append('file', fs.createReadStream(filePath));

    const response = await fetch(`${BASE_URL}/pdf/analyze`, {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${API_TOKEN}`,
        },
        body: form
    });

    const result = await response.json();
    
    if (result.success) {
        console.log(`Analysis ID: ${result.data.id}`);
        console.log(`Pages: ${result.data.metadata.page_count}`);
        console.log(`Remaining checks: ${result.remaining_checks}`);
    }
    
    return result;
}

// Usage
analyzePdf('/path/to/document.pdf');

准备好开始了吗?

创建免费账户并生成您的第一个API令牌即可开始集成。