С возвращением

Войдите для доступа к вашим документам и подписям

или продолжить с email
Забыли пароль?

🚀 Документация API

Интегрируйте обработку PDF в ваши приложения. Сжимайте, объединяйте, разделяйте PDF и извлекайте текст с помощью нашего мощного REST API.

✓ Включено в планы Premium и Business

🔐 Аутентификация

Все запросы к API требуют аутентификации с помощью Bearer токена. Получить API ключи можно в вашем личном кабинете.

Заголовок авторизации

Укажите ваш секретный ключ в заголовке Authorization:

Authorization: Bearer sk_live_your_secret_key_here

Лимиты запросов

60
запросов/минуту (default)
100 MB
максимальный размер файла
20
максимум файлов (объединение)

📦 Сжатие PDF

Уменьшите размер PDF файла с сохранением качества. Выберите между низким, средним или высоким уровнем сжатия.

POST https://pdf-ninja.io/api/v1/pdf/compress

Параметры

Параметр Тип Описание
pdf_base64 * string PDF файл в кодировке Base64 (или используйте pdf_url)
pdf_url string URL для загрузки PDF
level string Уровень сжатия: low, medium (по умолчанию), high
webhook_url optional string URL для получения результата по завершении обработки

Примеры кода

curl -X POST https://pdf-ninja.io/api/v1/pdf/compress \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "pdf_base64": "JVBERi0xLjQK...",
    "level": "medium"
  }'
<?php
$apiKey = 'sk_live_your_secret_key';
$pdfContent = base64_encode(file_get_contents('document.pdf'));

$ch = curl_init('https://pdf-ninja.io/api/v1/pdf/compress');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'pdf_base64' => $pdfContent,
        'level' => 'medium'
    ])
]);

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

if ($result['success']) {
    file_put_contents('compressed.pdf', base64_decode($result['data']['pdf_base64']));
    echo "Compressed! Saved " . $result['data']['savings_percent'] . "%";
}
?>
const apiKey = 'sk_live_your_secret_key';

// Read file and convert to base64
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const reader = new FileReader();

reader.onload = async function(e) {
    const base64 = e.target.result.split(',')[1];

    const response = await fetch('https://pdf-ninja.io/api/v1/pdf/compress', {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${apiKey}`,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            pdf_base64: base64,
            level: 'medium'
        })
    });

    const result = await response.json();

    if (result.success) {
        // Download compressed PDF
        const link = document.createElement('a');
        link.href = `data:application/pdf;base64,${result.data.pdf_base64}`;
        link.download = 'compressed.pdf';
        link.click();

        console.log(`Saved ${result.data.savings_percent}%`);
    }
};

reader.readAsDataURL(file);
import requests
import base64

api_key = 'sk_live_your_secret_key'

# Read PDF and encode to base64
with open('document.pdf', 'rb') as f:
    pdf_base64 = base64.b64encode(f.read()).decode('utf-8')

response = requests.post(
    'https://pdf-ninja.io/api/v1/pdf/compress',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'pdf_base64': pdf_base64,
        'level': 'medium'
    }
)

result = response.json()

if result['success']:
    # Save compressed PDF
    compressed_data = base64.b64decode(result['data']['pdf_base64'])
    with open('compressed.pdf', 'wb') as f:
        f.write(compressed_data)

    print(f"Saved {result['data']['savings_percent']}%")
const fs = require('fs');
const axios = require('axios');

const apiKey = 'sk_live_your_secret_key';

// Read PDF and encode to base64
const pdfBuffer = fs.readFileSync('document.pdf');
const pdfBase64 = pdfBuffer.toString('base64');

async function compressPdf() {
    const response = await axios.post(
        'https://pdf-ninja.io/api/v1/pdf/compress',
        {
            pdf_base64: pdfBase64,
            level: 'medium'
        },
        {
            headers: {
                'Authorization': `Bearer ${apiKey}`,
                'Content-Type': 'application/json'
            }
        }
    );

    if (response.data.success) {
        // Save compressed PDF
        const compressedBuffer = Buffer.from(
            response.data.data.pdf_base64,
            'base64'
        );
        fs.writeFileSync('compressed.pdf', compressedBuffer);

        console.log(`Saved ${response.data.data.savings_percent}%`);
    }
}

compressPdf();

✅ Успешный ответ

{
  "success": true,
  "data": {
    "pdf_base64": "JVBERi0xLjQK...",
    "original_size": 5242880,
    "compressed_size": 2621440,
    "savings_percent": 50.0,
    "method": "ghostscript"
  },
  "request_id": "abc123-def456"
}

📎 Объединение PDF

Объедините несколько PDF файлов в один документ. Поддерживается до 20 файлов.

POST https://pdf-ninja.io/api/v1/pdf/merge

Параметры

Параметр Тип Описание
files * array Массив PDF объектов с pdf_base64 или pdf_url
page_size string Размер страниц результата: original (по умолчанию), A4, A3, Letter

Примеры кода

curl -X POST https://pdf-ninja.io/api/v1/pdf/merge \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      {"pdf_base64": "JVBERi0xLjQK..."},
      {"pdf_url": "https://example.com/document.pdf"},
      {"pdf_base64": "JVBERi0xLjQK..."}
    ],
    "page_size": "A4"
  }'
<?php
$apiKey = 'sk_live_your_secret_key';

$files = [
    ['pdf_base64' => base64_encode(file_get_contents('doc1.pdf'))],
    ['pdf_base64' => base64_encode(file_get_contents('doc2.pdf'))],
    ['pdf_url' => 'https://example.com/doc3.pdf']
];

$ch = curl_init('https://pdf-ninja.io/api/v1/pdf/merge');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'files' => $files,
        'page_size' => 'A4'
    ])
]);

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

if ($result['success']) {
    file_put_contents('merged.pdf', base64_decode($result['data']['pdf_base64']));
    echo "Merged {$result['data']['files_count']} files, {$result['data']['total_pages']} pages";
}
?>
import requests
import base64

api_key = 'sk_live_your_secret_key'

files = []
for filename in ['doc1.pdf', 'doc2.pdf', 'doc3.pdf']:
    with open(filename, 'rb') as f:
        files.append({
            'pdf_base64': base64.b64encode(f.read()).decode('utf-8')
        })

response = requests.post(
    'https://pdf-ninja.io/api/v1/pdf/merge',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'files': files,
        'page_size': 'A4'
    }
)

result = response.json()

if result['success']:
    merged_data = base64.b64decode(result['data']['pdf_base64'])
    with open('merged.pdf', 'wb') as f:
        f.write(merged_data)

    print(f"Merged {result['data']['files_count']} files")

✅ Успешный ответ

{
  "success": true,
  "data": {
    "pdf_base64": "JVBERi0xLjQK...",
    "files_count": 3,
    "total_pages": 25,
    "size": 2048000,
    "method": "ghostscript"
  }
}

✂️ Разделение PDF

Разделите PDF на несколько файлов по страницам, диапазонам или равным частям.

POST https://pdf-ninja.io/api/v1/pdf/split

Параметры

Параметр Тип Описание
pdf_base64 * string PDF файл в кодировке Base64 (или используйте pdf_url)
mode string Режим разделения: pages (1 на страницу), range (произвольный), fixed (N страниц каждый), equal (N равных частей)
options object Опции для конкретного режима (см. примеры ниже)

Примеры кода

# Split by custom page ranges
curl -X POST https://pdf-ninja.io/api/v1/pdf/split \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "pdf_base64": "JVBERi0xLjQK...",
    "mode": "range",
    "options": {
      "pages": [[1, 2, 3], [4, 5], [6, 7, 8, 9, 10]]
    }
  }'

# Split into 3 equal parts
curl -X POST https://pdf-ninja.io/api/v1/pdf/split \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "pdf_base64": "JVBERi0xLjQK...",
    "mode": "equal",
    "options": {"num_files": 3}
  }'
import requests
import base64

api_key = 'sk_live_your_secret_key'

with open('document.pdf', 'rb') as f:
    pdf_base64 = base64.b64encode(f.read()).decode('utf-8')

# Split into fixed-size chunks (5 pages each)
response = requests.post(
    'https://pdf-ninja.io/api/v1/pdf/split',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'pdf_base64': pdf_base64,
        'mode': 'fixed',
        'options': {'pages_per_file': 5}
    }
)

result = response.json()

if result['success']:
    for i, file in enumerate(result['data']['files']):
        pdf_data = base64.b64decode(file['pdf_base64'])
        with open(f'split_{i+1}.pdf', 'wb') as f:
            f.write(pdf_data)
        print(f"Created split_{i+1}.pdf with pages {file['pages']}")

✅ Успешный ответ

{
  "success": true,
  "data": {
    "original_pages": 15,
    "files_count": 3,
    "files": [
      {
        "pdf_base64": "JVBERi0...",
        "pages": [1, 2, 3],
        "page_count": 3,
        "size": 512000,
        "name": "part_1"
      },
      ...
    ]
  }
}

👁️ OCR - Извлечение текста

Извлекайте текст из PDF и изображений с помощью оптического распознавания символов. Поддерживается 30+ языков.

POST https://pdf-ninja.io/api/v1/pdf/ocr

Параметры

Параметр Тип Описание
file_base64 * string PDF или изображение в кодировке Base64 (или используйте file_url)
language string Код языка: eng (по умолчанию), spa, fra, deu, ita, por, chi_sim, jpn, kor, ara...
output_format string Формат вывода: text (по умолчанию) или json (с разбивкой по страницам)

Примеры кода

curl -X POST https://pdf-ninja.io/api/v1/pdf/ocr \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "file_base64": "JVBERi0xLjQK...",
    "language": "eng",
    "output_format": "json"
  }'
import requests
import base64

api_key = 'sk_live_your_secret_key'

# OCR a scanned PDF in Spanish
with open('scanned_document.pdf', 'rb') as f:
    file_base64 = base64.b64encode(f.read()).decode('utf-8')

response = requests.post(
    'https://pdf-ninja.io/api/v1/pdf/ocr',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json={
        'file_base64': file_base64,
        'language': 'spa',
        'output_format': 'json'
    }
)

result = response.json()

if result['success']:
    print(f"Extracted {result['data']['word_count']} words")
    print(result['data']['text'])

✅ Успешный ответ

{
  "success": true,
  "data": {
    "text": "This is the extracted text from the document...",
    "word_count": 1234,
    "char_count": 5678,
    "method": "python",
    "pages": [
      {"page": 1, "text": "Page 1 content..."},
      {"page": 2, "text": "Page 2 content..."}
    ]
  }
}

📋 Проверка статуса задачи

Проверяйте статус и получайте результаты асинхронных задач.

GET https://pdf-ninja.io/api/v1/pdf/jobs/{job_id}

Примеры кода

# Get specific job status
curl https://pdf-ninja.io/api/v1/pdf/jobs/job_abc123 \
  -H "Authorization: Bearer sk_live_your_secret_key"

# List all jobs
curl "https://pdf-ninja.io/api/v1/pdf/jobs?status=completed&page=1" \
  -H "Authorization: Bearer sk_live_your_secret_key"

✅ Успешный ответ

{
  "success": true,
  "data": {
    "job_id": "job_abc123",
    "operation": "compress",
    "status": "completed",
    "created_at": "2025-01-05T12:00:00Z",
    "completed_at": "2025-01-05T12:00:05Z",
    "data": {
      "pdf_base64": "JVBERi0...",
      "savings_percent": 45.2
    }
  }
}

✍️ E-Signature API

Send documents for electronic signature. Create signature requests, track status, send reminders, and download signed documents with certificates.

Required Permissions

Your API key needs the following permissions for e-signature operations:

signature:create signature:read signature:cancel signature:remind

Create Signature Request

Send a document to one or more signers for electronic signature.

POST https://pdf-ninja.io/api/v1/signature-requests

Parameters

Name Type Description
title * string Document title shown to signers
signers * array Array of signers with name, email, and optional fields
pdf_base64 * string Base64-encoded PDF document (or use pdf_url)
pdf_url string URL to download PDF (alternative to pdf_base64)
message optional string Custom message to include in email to signers
expires_in_days optional integer Days until expiration (1-30, default: 7)
send_emails optional boolean Send email invitations automatically (default: true)
external_id optional string Your custom ID to reference this request
metadata optional object Custom metadata to store with the request
webhook_tag optional string Tag to filter which webhooks receive events for this request. Only webhooks with matching tag will be notified. Max 50 chars, alphanumeric with hyphens/underscores.

Signer Object

Name Type Description
name * string Signer's full name
email * string Signer's email address
order optional integer Signing order (for sequential signing)
fields optional array Signature fields (if empty, signer can place signature freely)

Field Types

signature Signature field (drawn or typed)
initials Initials field
date Date field (auto-filled)
name Full name field (auto-filled)
email Email field (auto-filled)
text Free text input
checkbox Checkbox field

Code Examples

curl -X POST https://pdf-ninja.io/api/v1/signature-requests \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Service Agreement",
    "message": "Please sign this agreement at your earliest convenience.",
    "signers": [
      {
        "name": "John Doe",
        "email": "[email protected]"
      },
      {
        "name": "Jane Smith",
        "email": "[email protected]",
        "fields": [
          {
            "type": "signature",
            "page": 1,
            "x": 100,
            "y": 500,
            "width": 200,
            "height": 60
          }
        ]
      }
    ],
    "pdf_base64": "JVBERi0xLjQK...",
    "external_id": "contract-2024-001",
    "expires_in_days": 14
  }'
<?php
$apiKey = 'sk_live_your_secret_key';
$pdfContent = base64_encode(file_get_contents('contract.pdf'));

$data = [
    'title' => 'Service Agreement',
    'message' => 'Please sign this agreement.',
    'signers' => [
        [
            'name' => 'John Doe',
            'email' => '[email protected]'
        ],
        [
            'name' => 'Jane Smith',
            'email' => '[email protected]'
        ]
    ],
    'pdf_base64' => $pdfContent,
    'external_id' => 'contract-2024-001',
    'expires_in_days' => 14
];

$ch = curl_init('https://pdf-ninja.io/api/v1/signature-requests');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey,
        'Content-Type: application/json'
    ],
    CURLOPT_POSTFIELDS => json_encode($data)
]);

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

if ($result['success']) {
    echo "Signature request created: " . $result['data']['id'] . "\n";

    // Get signing URLs for each signer
    foreach ($result['data']['signers'] as $signer) {
        echo $signer['name'] . ": " . $signer['sign_url'] . "\n";
    }
}
?>
import requests
import base64

api_key = 'sk_live_your_secret_key'

# Read PDF and encode to base64
with open('contract.pdf', 'rb') as f:
    pdf_base64 = base64.b64encode(f.read()).decode('utf-8')

data = {
    'title': 'Service Agreement',
    'message': 'Please sign this agreement.',
    'signers': [
        {'name': 'John Doe', 'email': '[email protected]'},
        {'name': 'Jane Smith', 'email': '[email protected]'}
    ],
    'pdf_base64': pdf_base64,
    'external_id': 'contract-2024-001',
    'expires_in_days': 14
}

response = requests.post(
    'https://pdf-ninja.io/api/v1/signature-requests',
    headers={
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    },
    json=data
)

result = response.json()

if result.get('success'):
    print(f"Created: {result['data']['id']}")

    # Get signing URLs
    for signer in result['data']['signers']:
        print(f"{signer['name']}: {signer['sign_url']}")
const apiKey = 'sk_live_your_secret_key';

// Convert file to base64
async function fileToBase64(file) {
    return new Promise((resolve) => {
        const reader = new FileReader();
        reader.onload = () => resolve(reader.result.split(',')[1]);
        reader.readAsDataURL(file);
    });
}

async function createSignatureRequest(file) {
    const pdfBase64 = await fileToBase64(file);

    const response = await fetch('https://pdf-ninja.io/api/v1/signature-requests', {
        method: 'POST',
        headers: {
            'Authorization': `Bearer ${apiKey}`,
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            title: 'Service Agreement',
            message: 'Please sign this agreement.',
            signers: [
                { name: 'John Doe', email: '[email protected]' },
                { name: 'Jane Smith', email: '[email protected]' }
            ],
            pdf_base64: pdfBase64,
            external_id: 'contract-2024-001',
            expires_in_days: 14
        })
    });

    const result = await response.json();

    if (result.success) {
        console.log('Created:', result.data.id);

        // Signing URLs for embedding or redirecting
        result.data.signers.forEach(signer => {
            console.log(`${signer.name}: ${signer.sign_url}`);
        });
    }

    return result;
}

✅ Success Response

{
  "success": true,
  "data": {
    "id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
    "status": "pending",
    "title": "Service Agreement",
    "signers": [
      {
        "name": "John Doe",
        "email": "[email protected]",
        "order": 1,
        "status": "pending",
        "sign_url": "https://pdf-ninja.io/pdf_esignature_sign.php?token=abc123..."
      },
      {
        "name": "Jane Smith",
        "email": "[email protected]",
        "order": 2,
        "status": "pending",
        "sign_url": "https://pdf-ninja.io/pdf_esignature_sign.php?token=def456..."
      }
    ],
    "external_id": "contract-2024-001",
    "created_at": "2024-01-15T10:30:00Z",
    "expires_at": "2024-01-29T10:30:00Z"
  },
  "request_id": "req_xyz789"
}

List Signature Requests

Retrieve a paginated list of your signature requests with optional filters.

GET https://pdf-ninja.io/api/v1/signature-requests

Query Parameters

page integer Page number (default: 1)
per_page integer Items per page (1-100, default: 20)
status string Filter by status: pending, in_progress, completed, cancelled, expired
external_id string Filter by your external ID
# List all signature requests
curl "https://pdf-ninja.io/api/v1/signature-requests?page=1&per_page=20" \
  -H "Authorization: Bearer sk_live_your_secret_key"

# Filter by status
curl "https://pdf-ninja.io/api/v1/signature-requests?status=completed" \
  -H "Authorization: Bearer sk_live_your_secret_key"

# Find by external ID
curl "https://pdf-ninja.io/api/v1/signature-requests?external_id=contract-2024-001" \
  -H "Authorization: Bearer sk_live_your_secret_key"

Get Signature Request Details

Retrieve detailed information about a specific signature request including signer status.

GET https://pdf-ninja.io/api/v1/signature-requests/{id}
curl https://pdf-ninja.io/api/v1/signature-requests/sr_a1b2c3d4e5f6g7h8i9j0k1l2 \
  -H "Authorization: Bearer sk_live_your_secret_key"

✅ Success Response

{
  "success": true,
  "data": {
    "id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
    "status": "completed",
    "title": "Service Agreement",
    "message": "Please sign this agreement.",
    "signers": [
      {
        "name": "John Doe",
        "email": "[email protected]",
        "order": 1,
        "status": "signed",
        "signed_at": "2024-01-16T14:22:00Z",
        "signature_hash": "a1b2c3d4e5f6..."
      },
      {
        "name": "Jane Smith",
        "email": "[email protected]",
        "order": 2,
        "status": "signed",
        "signed_at": "2024-01-17T09:15:00Z",
        "signature_hash": "f6e5d4c3b2a1..."
      }
    ],
    "external_id": "contract-2024-001",
    "metadata": {"department": "sales"},
    "created_at": "2024-01-15T10:30:00Z",
    "expires_at": "2024-01-29T10:30:00Z",
    "completed_at": "2024-01-17T09:15:00Z",
    "download_url": "/api/v1/signature-requests/sr_a1b2c3.../download",
    "certificate_url": "/api/v1/signature-requests/sr_a1b2c3.../certificate"
  }
}

Download Signed PDF

Download the signed PDF document (only available for completed requests).

GET https://pdf-ninja.io/api/v1/signature-requests/{id}/download
curl https://pdf-ninja.io/api/v1/signature-requests/sr_a1b2c3.../download \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -o signed_document.pdf
<?php
$apiKey = 'sk_live_your_secret_key';
$requestId = 'sr_a1b2c3d4e5f6g7h8i9j0k1l2';

$ch = curl_init("https://pdf-ninja.io/api/v1/signature-requests/{$requestId}/download");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $apiKey
    ]
]);

$pdfContent = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpCode === 200) {
    file_put_contents('signed_contract.pdf', $pdfContent);
    echo "Downloaded signed document!";
}
?>

Download Certificate

Download the signature certificate (HTML) with audit trail and signature hashes.

GET https://pdf-ninja.io/api/v1/signature-requests/{id}/certificate
curl https://pdf-ninja.io/api/v1/signature-requests/sr_a1b2c3.../certificate \
  -H "Authorization: Bearer sk_live_your_secret_key" \
  -o signature_certificate.html

Cancel Signature Request

Cancel a pending or in-progress signature request. Cannot cancel completed requests.

POST https://pdf-ninja.io/api/v1/signature-requests/{id}/cancel
curl -X POST https://pdf-ninja.io/api/v1/signature-requests/sr_a1b2c3.../cancel \
  -H "Authorization: Bearer sk_live_your_secret_key"

✅ Success Response

{
  "success": true,
  "data": {
    "id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
    "status": "cancelled",
    "cancelled_at": "2024-01-18T11:00:00Z"
  }
}

Send Reminder

Send email reminders to all signers who haven't signed yet.

POST https://pdf-ninja.io/api/v1/signature-requests/{id}/remind
curl -X POST https://pdf-ninja.io/api/v1/signature-requests/sr_a1b2c3.../remind \
  -H "Authorization: Bearer sk_live_your_secret_key"

✅ Success Response

{
  "success": true,
  "data": {
    "id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
    "reminders_sent": 1,
    "reminded_emails": ["[email protected]"]
  }
}

E-Signature Webhooks

Receive real-time notifications when signature events occur.

Available Events

signature_request.created Signature request was created
signature_request.signed A signer completed their signature
signature_request.completed All signers have signed
signature_request.cancelled Request was cancelled
signature_request.expired Request expired without completion

📩 Webhook Payload Example

POST /your-webhook-endpoint HTTP/1.1
Content-Type: application/json
X-PDF-Ninja-Event: signature_request.completed
X-PDF-Ninja-Signature: sha256=abc123...

{
  "event": "signature_request.completed",
  "signature_request_id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
  "data": {
    "id": "sr_a1b2c3d4e5f6g7h8i9j0k1l2",
    "title": "Service Agreement",
    "status": "completed",
    "external_id": "contract-2024-001",
    "metadata": {"department": "sales"},
    "completed_at": "2024-01-17T09:15:00Z"
  },
  "timestamp": "2024-01-17T09:15:00Z"
}

🔔 Webhooks

Получайте уведомления о завершении асинхронных задач. Добавьте webhook_url к любому запросу для включения асинхронного режима.

Webhook Tags

Use tags to route events to specific webhooks. This is useful when you have multiple workflows (e.g., contracts, offers, HR documents) and want different endpoints to handle different types of signature requests.

How it works:
  1. Create webhooks with tags: When creating a webhook via API or dashboard, assign a tag like "contracts" or "hr"
  2. Specify tag when creating signature requests: Add webhook_tag: "contracts" to your signature request
  3. Events are filtered: Only webhooks with matching tag receive the events
// Creating a webhook with tag
POST /api/v1/webhooks
{
  "url": "https://your-server.com/contracts-webhook",
  "events": ["signature_request.completed"],
  "tag": "contracts"
}

// Creating a signature request that targets this webhook
POST /api/v1/signature-requests
{
  "title": "Service Agreement",
  "webhook_tag": "contracts",  // Only webhooks with tag="contracts" will receive events
  "signers": [...]
}

Данные Webhook

После завершения задачи мы отправляем POST запрос на ваш webhook URL со следующими данными:

📩 Webhook запрос

POST /your-webhook-endpoint HTTP/1.1
Host: your-server.com
Content-Type: application/json
X-PDF-Ninja-Event: pdf.compress.completed
X-PDF-Ninja-Job-ID: job_abc123
X-PDF-Ninja-Signature: sha256=abc123...

{
  "event": "pdf.compress.completed",
  "job_id": "job_abc123",
  "data": {
    "pdf_base64": "JVBERi0...",
    "original_size": 5000000,
    "compressed_size": 2500000,
    "savings_percent": 50.0
  },
  "timestamp": "2025-01-05T12:00:00Z"
}

Проверка Webhooks

Если вы указали webhook_secret, мы подписываем данные с помощью HMAC-SHA256. Проверьте подпись для подтверждения подлинности:

<?php
$webhookSecret = 'your_webhook_secret';
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_PDF_NINJA_SIGNATURE'] ?? '';

// Extract hash from "sha256=xxx" format
$expectedSignature = 'sha256=' . hash_hmac('sha256', $payload, $webhookSecret);

if (hash_equals($expectedSignature, $signature)) {
    $data = json_decode($payload, true);
    // Process the webhook
    echo "Valid webhook received!";
} else {
    http_response_code(401);
    echo "Invalid signature";
}
?>
import hmac
import hashlib
from flask import Flask, request

app = Flask(__name__)
WEBHOOK_SECRET = 'your_webhook_secret'

@app.route('/webhook', methods=['POST'])
def handle_webhook():
    payload = request.data
    signature = request.headers.get('X-PDF-Ninja-Signature', '')

    expected = 'sha256=' + hmac.new(
        WEBHOOK_SECRET.encode(),
        payload,
        hashlib.sha256
    ).hexdigest()

    if hmac.compare_digest(expected, signature):
        data = request.json
        print(f"Received: {data['event']}")
        return 'OK', 200
    else:
        return 'Invalid signature', 401
PDF-Ninja для Gmail - Расширение Chrome

Открывайте PDF-вложения из Gmail прямо в PDF-Ninja. Редактируйте, подписывайте и конвертируйте PDF мгновенно!

Установить бесплатное расширение

Wait — don't miss out!

Subscribe for free PDF tips, new tools, and feature updates delivered to your inbox.

No spam ever. Unsubscribe anytime.