Search by

spoolpdf / sdk-php

randidwinandra

Official PHP client for the spoolpdf HTML/URL to PDF API

v0.1.0 2026-08-19 04:12 UTC

This package is auto-updated.

Last update: 2026-08-19 04:39:08 UTC


README

Official PHP client for POST /v1/render. Defaults to production https://spoolpdf-api.nandra.dev.

Requirements

  • PHP 8.1+
  • ext-curl (default HTTP transport)

Installation

composer require spoolpdf/sdk-php

Usage

<?php
require __DIR__ . '/vendor/autoload.php';

use Spoolpdf\Sdk\Client;
use Spoolpdf\Sdk\SpoolPdfException;

$client = new Client(getenv('SPOOLPDF_API_KEY') ?: '');

try {
    $bytes = $client->render([
        'html' => '<h1>Hello spoolpdf</h1>',
        'format' => 'A4',
        'print_background' => true,
    ]);
    file_put_contents('out.pdf', $bytes);

    $meta = $client->renderWithMeta(['html' => '<p>with headers</p>']);
    // $meta['bytes'], $meta['requestId'], $meta['usageCount'], $meta['contentType']
} catch (SpoolPdfException $e) {
    // $e->getStatus(), $e->getErrorCode(), $e->getRequestId(), $e->getBody()
    throw $e;
}

Local Compose API:

$client = new Client(getenv('SPOOLPDF_API_KEY') ?: '', 'http://localhost:8080');

Create a key at spoolpdf.nandra.dev/keys.

Client API

  • new Client(string $apiKey, ?string $baseUrl = null, ?callable $http = null)
  • render(array $input): string — PDF bytes
  • renderWithMeta(array $input): arraybytes, requestId, usageCount, contentType
  • SpoolPdfException on non-2xx (and transport failures)

Exactly one of html or url is required. Prefer html for speed and to avoid ssrf_blocked on private hosts.

Optional $http is for tests: (string $method, string $url, array $headers, string $body): array{status,headers,body}.

Tests

cd sdk-php
composer install
./vendor/bin/phpunit

License

MIT