Developer guide

Easy integration, any stack

Drop in the SDK or call the REST API directly — grab a key, paste a snippet, and your first PDF is rendering in minutes.

Step 1

Get an API key

Create a free account and copy your API key from the dashboard.

Sign up
Step 2

Install the SDK

Use the PHP / Laravel SDK for the cleanest integration. Or call the API directly with curl.

PHP SDK on GitHub
Step 3

Generate a PDF

Send HTML or a URL. Receive PDF bytes back. That's it.

API reference

PHP / Laravel SDK

One fluent builder per API field. Auto-discovered Laravel service provider, facade, and config. Typed exceptions so validation errors flow into your existing form-error UI.

Install
composer require htmltopdfapi/php-sdk
.env (Laravel)
HTML_TO_PDF_API_KEY=sk_live_xxxxxxxxxxxxxxxx
Generate an invoice PDF (Laravel)
use HtmlToPdfApi\Laravel\Facades\HtmlToPdf;

Route::get('/invoices/{invoice}.pdf', function (Invoice $invoice, Request $request) {
    $html = view('invoices.pdf', compact('invoice'))->render();

    return HtmlToPdf::html($html)
        ->paperSize('a4')
        ->margins(top: 25, bottom: 25)
        ->footer('<div class="text-center">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>')
        ->waitUntil('networkidle0')
        ->generate()
        ->toResponse($request);
});
Plain PHP — URL to disk
use HtmlToPdfApi\HtmlToPdf;

$sdk = new HtmlToPdf(['api_key' => getenv('HTML_TO_PDF_API_KEY')]);

$sdk->url('https://example.com/dashboard')
    ->landscape()
    ->waitUntil('networkidle0')
    ->retina()
    ->generate()
    ->saveAs('/tmp/dashboard.pdf');
Typed error handling
use HtmlToPdfApi\Exceptions\ValidationException;

try {
    $pdf = HtmlToPdf::html($html)->generate();
} catch (ValidationException $e) {
    foreach ($e->errors() as $field => $messages) {
        report("[$field] " . $messages[0]);
    }
}

No SDK? Use raw HTTP

Any HTTP client works. Bearer token auth, JSON body, PDF bytes back. The full request shape is documented in the API reference.

curl
curl -X POST https://platform.htmltopdfapi.co/api/v1/pdf/generate \
  -H "Authorization: Bearer sk_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello world</h1>",
    "paper_size": "a4",
    "margin_top": 25,
    "margin_bottom": 25,
    "footer_html": "<div style=\"text-align:center;font-size:9px\">Page <span class=\"pageNumber\"></span></div>"
  }' \
  --output document.pdf

Error responses

Every error response uses the same envelope so you can parse it once and reuse it everywhere.

StatusMeaningWhat to do
401Bad / missing API keyVerify the Bearer token; rotate if compromised.
422Request validation failedRead errors map: { field → [messages] }; surface inline.
429Plan quota exceededWait for the reset window or upgrade plan.
5xxServer errorRetry with backoff. Persistent? Email support.