HTML to PDF in PHP
DomPDF chokes on flexbox and grid. mPDF is better but still not a browser. wkhtmltopdf means shipping a binary to your host — if your host even allows it. A rendering API turns all of that into one cURL call that works on any PHP host, shared hosting included.
1. Convert HTML to PDF with cURL
<?php
$ch = curl_init('https://inkpdf.dev/v1/pdf');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('INKPDF_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'html' => '<h1>Hello from PHP</h1><p>Flexbox and grid just work.</p>',
'options' => ['format' => 'A4'],
]),
]);
$pdf = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
$err = json_decode($pdf, true);
throw new RuntimeException($err['message'] ?? 'render failed');
}
file_put_contents('hello.pdf', $pdf);2. Invoice from an array (no HTML)
Post data against a built-in template — line totals, tax, and grand total are computed server-side:
$payload = [
'template' => 'invoice',
'data' => [
'brand' => ['name' => 'Acme Studio', 'color' => '#0f766e'],
'invoiceNumber' => 'INV-2043',
'issueDate' => '2026-07-01',
'dueDate' => '2026-07-31',
'currency' => 'USD',
'to' => ['name' => 'Northwind Traders', 'address' => '1 Market St, SF'],
'items' => [
['description' => 'Design work', 'quantity' => 10, 'unitPrice' => 95],
],
'taxRate' => 8.5,
],
];3. Laravel: PDF download response
use Illuminate\Support\Facades\Http;
Route::get('/invoice/{id}', function (string $id) {
$res = Http::withToken(config('services.inkpdf.key'))
->timeout(60)
->post('https://inkpdf.dev/v1/pdf', [
'template' => 'invoice',
'data' => Invoice::findOrFail($id)->toTemplateData(),
]);
abort_unless($res->ok(), 502, $res->json('message'));
return response($res->body(), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => "attachment; filename=\"{$id}.pdf\"",
]);
});4. WordPress: PDF of any page
URL mode renders any public page — useful for turning posts or order confirmations into PDFs:
$res = wp_remote_post('https://inkpdf.dev/v1/pdf', [
'timeout' => 60,
'headers' => [
'Authorization' => 'Bearer ' . INKPDF_KEY,
'Content-Type' => 'application/json',
],
'body' => wp_json_encode(['url' => get_permalink($post_id)]),
]);
$pdf = wp_remote_retrieve_body($res);Options cheat sheet
| Option | Example |
|---|---|
| format | "Letter", "A4", "Legal"… |
| landscape | true |
| margin | ["top" => "1in", "bottom" => "20mm"] |
| footerTemplate | page numbers via <span class="pageNumber"> |
Full reference in the API docs.
Try it without writing code
The playground renders live against the real pipeline — 20 free renders a day, no signup.