Guides / PHP
Invoices, contracts, reports, certificates: every product eventually needs PDFs, and PHP PDF libraries make you hand-position every box. RasterKit prints through real Chromium instead — write ordinary HTML and CSS, POST it, get a finished PDF back.
Because it's a print pipeline rather than a drawing API, you keep your existing templates and stylesheets: flexbox, grid, web fonts, page-break CSS, repeating headers and footers with page numbers all just work.
Sign up free (magic link, no card) — your key is shown right after sign-in. You get 100 renders/month free across screenshots, PDFs, and images.
<?php
$ch = curl_init('https://rasterkit.com/v1/pdf');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_HTTPHEADER => [
'x-api-key: ' . getenv('RASTERKIT_API_KEY'),
'content-type: application/json',
],
CURLOPT_POSTFIELDS => '{"url": "https://example.com/invoice/42", "format": "A4", "print_background": true}',
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status !== 200) {
throw new RuntimeException("Render failed: $status $body");
}
file_put_contents('document.pdf', $body);
echo "Saved document.pdf\n"; The response body is the file itself — no JSON envelope to unwrap, no second download request. Errors come back as JSON with a stable error code.
The PDF API reference documents every parameter. The ones people reach for first:
format: "Letter", landscape: true — paper setupfooter_template — page numbers via <span class="pageNumber">print_background: true — keep your CSS backgrounds (on by default)wait_for_selector — wait for charts/data before printingPass footer_template with Chromium's built-in classes, e.g. <span class="pageNumber"></span> / <span class="totalPages"></span>.
Browsers skip backgrounds when printing by default. RasterKit sets print_background: true by default — if you turned it off, turn it back on.
Yes — standard CSS (break-inside: avoid, break-after: page) is respected, and prefer_css_page_size lets your @page rules define the paper size.