← toolkit.bot

PDF to EPUB Conversion in WordPress — Plugins and API Integration

June 12, 2026  ·  7 min read

Running a WordPress site that needs to offer EPUB downloads from PDF uploads? Here are the options — from simple plugins to a custom API integration with toolkit.bot.

Option 1: Manual Workflow (Simplest)

For low-volume needs (a few PDFs per month), convert manually and upload the EPUB as a media file:

  1. Convert your PDF with toolkit.bot
  2. Upload the EPUB to WordPress Media Library
  3. Link to the EPUB file in your post or page

No plugin needed. Best for publishers, course creators, or anyone adding EPUBs as downloadable resources.

Option 2: WooCommerce Digital Download

For selling EPUB files:

  1. Convert your PDF to EPUB via toolkit.bot
  2. In WooCommerce, create a product → set as Virtual + Downloadable
  3. Upload the EPUB as the downloadable file

Customers receive a download link after purchase. No conversion plugin needed — just manual prep of the EPUB file.

Option 3: Custom PHP Integration (Automated)

For sites that need to auto-convert uploaded PDFs to EPUB (e.g., a document library, an academic repository), add a hook to your theme's functions.php or a custom plugin:

<?php
// Trigger EPUB conversion when a PDF is uploaded to WordPress
add_filter('wp_handle_upload', function($upload) {
    if ($upload['type'] !== 'application/pdf') {
        return $upload;
    }

    $api_key = defined('TOOLKIT_BOT_API_KEY')
        ? TOOLKIT_BOT_API_KEY : get_option('toolkit_bot_api_key');
    if (!$api_key) return $upload;

    // Submit to toolkit.bot
    $response = wp_remote_post('https://toolkit.bot/api/v1/convert', [
        'timeout' => 30,
        'headers' => ['Authorization' => 'Bearer ' . $api_key],
        'body'    => [
            'output_format'  => 'epub3',
            'webhook_url'    => home_url('/toolkit-webhook'),
        ],
        // File upload requires multipart — use wp_remote_post with boundary
    ]);

    // Store job_id in post meta for status tracking
    $job = json_decode(wp_remote_retrieve_body($response), true);
    if (!empty($job['job_id'])) {
        update_option('toolkit_pending_' . $job['job_id'],
                      $upload['file']);
    }

    return $upload;
});

// Webhook endpoint to receive completed conversion
add_action('init', function() {
    if ($_SERVER['REQUEST_URI'] === '/toolkit-webhook'
        && $_SERVER['REQUEST_METHOD'] === 'POST') {
        $payload = json_decode(file_get_contents('php://input'), true);
        if ($payload['event'] === 'job.complete') {
            $pdf_path = get_option('toolkit_pending_' . $payload['job_id']);
            $epub_url = $payload['download_url'];
            $api_key  = get_option('toolkit_bot_api_key');

            // Download the EPUB
            $epub = wp_remote_get($epub_url, [
                'headers' => ['Authorization' => 'Bearer ' . $api_key]
            ]);
            $epub_path = str_replace('.pdf', '.epub', $pdf_path);
            file_put_contents($epub_path,
                              wp_remote_retrieve_body($epub));

            // Clean up pending record
            delete_option('toolkit_pending_' . $payload['job_id']);
        }
        exit;
    }
});

Option 4: REST API Endpoint for Front-End Upload

Expose a WordPress REST endpoint so a JavaScript front-end can trigger conversion:

<?php
add_action('rest_api_init', function() {
    register_rest_route('toolkit/v1', '/convert', [
        'methods'             => 'POST',
        'callback'            => 'toolkit_convert_pdf',
        'permission_callback' => function() {
            return current_user_can('upload_files');
        },
    ]);
});

function toolkit_convert_pdf(WP_REST_Request $request): WP_REST_Response {
    $file    = $request->get_file_params()['file'];
    $api_key = defined('TOOLKIT_BOT_API_KEY') ? TOOLKIT_BOT_API_KEY : '';

    // Submit to toolkit.bot (using cURL for multipart)
    $curl = curl_init('https://toolkit.bot/api/v1/convert');
    curl_setopt_array($curl, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST           => true,
        CURLOPT_HTTPHEADER     => ['Authorization: Bearer ' . $api_key],
        CURLOPT_POSTFIELDS     => [
            'file'          => new CURLFile($file['tmp_name'], 'application/pdf'),
            'output_format' => 'epub3',
        ],
    ]);
    $body = json_decode(curl_exec($curl), true);
    curl_close($curl);

    return new WP_REST_Response(['job_id' => $body['job_id']], 202);
}

Configuration: Store the API Key Safely

<?php
// In wp-config.php (not functions.php — keeps key out of database)
define('TOOLKIT_BOT_API_KEY', 'tk_live_your_key_here');
Get your toolkit.bot API key →