Docs
PHP SDK
Use composer require relaypdf/relaypdf in PHP 8.1+ when you want the official client instead of raw curl. Request JSON field names match REST; methods are camelCase. The package README is the full method and error reference.
The official PHP SDK uses ext-curl and ext-json and mirrors the Node client. Field names in request bodies match REST. Methods are camelCase.
Installation
Requires PHP 8.1+ with curl, json, and hash.
Package: relaypdf/relaypdf. Current line is 0.1.x. Until Packagist publish, require the path in this repo. The README is the full method and error reference.
composer require relaypdf/relaypdfQuick start
apiKey is required. Load RELAYPDF_API_KEY from the env file written by relaypdf setup.
<?php
use RelayPDF\RelayPDF;
$client = new RelayPDF(getenv('RELAYPDF_API_KEY'));
$pdf = $client->pdf->fromHtml(
'<h1>Invoice #1042</h1><p>Total: $1,200.00</p>',
['filename' => 'invoice.pdf'],
);
$pdf->save('invoice.pdf');URL, Markdown, templates
Same sources as REST. fromTemplate takes a published template id or slug plus an array.
$pdf = $client->pdf->fromUrl('https://example.com', [
'filename' => 'page.pdf',
'options' => ['format' => 'A4', 'printBackground' => true],
]);
$md = $client->pdf->fromMarkdown("# Hello\n\nFrom **Markdown**.");
$invoice = $client->pdf->fromTemplate('invoice', ['number' => 'INV-1042', 'total' => 1458], [
'filename' => 'invoice.pdf',
'strict' => true,
]);Binary, URL, and async results
Default is binary with save(). response=url returns a 24-hour link. response=async returns a job; wait then download.
$urlResult = $client->pdf->fromHtml('<h1>Hi</h1>', ['response' => 'url']);
$job = $client->convert->fromPath('deck.pptx', ['to' => 'pdf', 'response' => 'async']);
$done = $client->jobs->wait($job->id);
$client->files->download($done['id'])->save('deck.pdf');Errors
HTTP failures throw RelayPDFError with status, code, message, and optional retryAfter.
try {
$client->pdf->fromUrl('https://example.com');
} catch (RelayPDF\RelayPDFError $err) {
echo $err->status, $err->code, $err->getMessage(), $err->retryAfter;
}SDK reference
JSON bodies keep REST camelCase. Methods are camelCase. The Composer README lists every helper.
| Method | HTTP | Description |
|---|---|---|
| health() / account() | GET /health · /v1/account | Liveness and wallet. Account is not billed. |
| pdf.fromHtml / fromUrl / fromMarkdown / fromTemplate / create | POST /v1/pdf | HTML, URL, Markdown, or template → PDF |
| pdf.merge / extract / protect / unlock / bookmarks / raster / fromImages / stamp / rotate / deletePages / compress / info / text / formFields / formFill | POST /v1/pdf/* | PDF tools |
| images.fromHtml / fromUrl | POST /v1/images | Screenshot |
| convert.create / fromHtml / fromPath / wkhtml | POST /v1/convert | LibreOffice or wkhtmltopdf |
| templates.* | /v1/templates | Handlebars drafts including preview/generate |
| barcodes.create / qr · zip.create | POST /v1/barcodes · /v1/zip | Barcode, QR, zip |
| jobs.get / wait · files.download | GET /v1/jobs/:id · /v1/files/:id | Poll and 24h download |
| Webhooks::verify | RelayPDF-Signature | HMAC-SHA256 |