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
composer require relaypdf/relaypdf

Quick start

apiKey is required. Load RELAYPDF_API_KEY from the env file written by relaypdf setup.

index.php
<?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.

fromUrl / fromMarkdown / fromTemplate
$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.

response modes
$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.

RelayPDFError
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.

MethodHTTPDescription
health() / account()GET /health · /v1/accountLiveness and wallet. Account is not billed.
pdf.fromHtml / fromUrl / fromMarkdown / fromTemplate / createPOST /v1/pdfHTML, URL, Markdown, or template → PDF
pdf.merge / extract / protect / unlock / bookmarks / raster / fromImages / stamp / rotate / deletePages / compress / info / text / formFields / formFillPOST /v1/pdf/*PDF tools
images.fromHtml / fromUrlPOST /v1/imagesScreenshot
convert.create / fromHtml / fromPath / wkhtmlPOST /v1/convertLibreOffice or wkhtmltopdf
templates.*/v1/templatesHandlebars drafts including preview/generate
barcodes.create / qr · zip.createPOST /v1/barcodes · /v1/zipBarcode, QR, zip
jobs.get / wait · files.downloadGET /v1/jobs/:id · /v1/files/:idPoll and 24h download
Webhooks::verifyRelayPDF-SignatureHMAC-SHA256