spoolpdf / sdk-php
Official PHP client for the spoolpdf HTML/URL to PDF API
v0.1.0
2026-08-19 04:12 UTC
Requires
- php: >=8.1
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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 bytesrenderWithMeta(array $input): array—bytes,requestId,usageCount,contentTypeSpoolPdfExceptionon 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