Website screenshots & PDFs in PHP

No wkhtmltopdf binaries and no Puppeteer sidecar. Plain cURL (or Guzzle) gets you a screenshot or PDF.

1. Get an API key

Click Get free key. You get 25 free renders a month instantly, no account needed. Store the key in an environment variable called SHOTMINT_KEY.

2. Screenshot a URL

<?php
$query = http_build_query(['url' => 'https://example.com', 'full_page' => 'true']);
$ch = curl_init("https://shotmint.creasework.com/v1/screenshot?$query");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('SHOTMINT_KEY')],
    CURLOPT_TIMEOUT => 60,
]);
$png = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) die("Render failed: $png");
file_put_contents('shot.png', $png);

Useful parameters: full_page=true for the whole scrollable page, width/height for the viewport, device_scale_factor=2 for retina, selector to capture a single element, dark_mode=true, and hide_selectors to remove cookie banners. See the full list.

3. Turn HTML into a PDF

<?php
$ch = curl_init("https://shotmint.creasework.com/v1/pdf");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('SHOTMINT_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode(['html' => '<h1>Invoice #42</h1>', 'format' => 'A4']),
]);
file_put_contents('invoice.pdf', curl_exec($ch));

PDF options include format (A4, Letter…), landscape, margin, and print_background. You can pass a url instead of html.

Errors & credits

A failed render never costs a credit. Status 400 means bad input or an unreachable URL, 402 means you're out of credits, and 429/503 mean you should retry with backoff. Every successful response includes an X-Credits-Remaining header, and screenshots and PDFs of a URL also carry X-Page-Status: the HTTP status the site answered with. A 403 there usually means you captured the site's bot-protection page, a 404 its error page.

Notes for PHP

In Laravel: Http::withHeaders(['X-API-Key' => env('SHOTMINT_KEY')])->post($url, ['html' => view('invoice', $data)->render()])->body().

Production version: retries, timeouts and page status

The quickstart above stops at the first error. In production you want three more things: retry only the failures that can fix themselves (503 when the renderer is busy, network timeouts), never retry a 400 or 402, and warn when the site itself answered with an error page. This script does all three for screenshots and PDFs, and prints the credits left after each call:

<?php
const API = 'https://shotmint.creasework.com';

// Retries only what is worth retrying: 503 (renderer busy) and network errors.
// A 400 (bad input, unreachable site) or 402 (no credits) will not fix itself.
function render(string $path, array $params, int $attempts = 3): string
{
    for ($i = 0; $i < $attempts; $i++) {
        if ($i > 0) sleep(2 ** ($i - 1));
        $headers = [];
        $ch = curl_init(API . $path);
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => json_encode($params),
            CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('SHOTMINT_KEY'), 'Content-Type: application/json'],
            CURLOPT_CONNECTTIMEOUT => 10,
            CURLOPT_TIMEOUT => 90,
            CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
                $parts = explode(':', $line, 2);
                if (count($parts) === 2) $headers[strtolower(trim($parts[0]))] = trim($parts[1]);
                return strlen($line);
            },
        ]);
        $body = curl_exec($ch);
        $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($body === false || $status === 503) continue;
        if ($status !== 200) {
            throw new RuntimeException("$status: " . (json_decode($body, true)['error'] ?? $body));
        }
        if ((int) ($headers['x-page-status'] ?? 0) >= 400) {
            error_log("site answered {$headers['x-page-status']}: you may have captured an error or bot page");
        }
        error_log('credits left: ' . $headers['x-credits-remaining']);
        return $body;
    }
    throw new RuntimeException("render failed after $attempts attempts");
}

file_put_contents('shot.png', render('/v1/screenshot', ['url' => 'https://en.wikipedia.org/wiki/PHP', 'full_page' => true]));
file_put_contents('page.pdf', render('/v1/pdf', ['url' => 'https://example.com', 'format' => 'A4']));

cURL has no total timeout by default (CURLOPT_TIMEOUT 0 means wait forever), so set one. PHP's cURL has no built-in way to read single response headers, so CURLOPT_HEADERFUNCTION collects them for X-Page-Status and X-Credits-Remaining.

Timing, measured on 2026-10-25: a full-page capture of a long Wikipedia article plus an A4 PDF took 8.5 to 25 s end to end, so keep the read timeout well above 30 s. Full-page captures are capped at 16,000 px tall (the Go and PHP articles hit that cap). With a format the API doesn't support, the script stops at once with the API's own message: 400: format must be png, jpeg or webp (got "gif").

Try it with 25 free renders a month

No signup, no card. Get a key in one click, then buy credits only if you need more (from €5 for 2,000, never expire). From a script, an AI agent, Make or Zapier, POST /v1/keys/free (no body) returns a key as JSON (openapi.json, no-code recipes).

Get a free API key Full API reference

More guides: API quickstarts by language

All guides: guides · integrations · comparisons