Complete PHP code examples for the PixDoc API
# Uses PHP's built-in cURL extensionSend HTML to the /api/v1/pdf endpoint and save the binary response.
$ch = curl_init("https://pixdoc.dev/api/v1/pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode(["html" => "<h1>Hello World</h1>"]),
CURLOPT_RETURNTRANSFER => true,
]);
$pdf = curl_exec($ch);
file_put_contents("output.pdf", $pdf);The /api/v1/screenshot endpoint returns a PNG image.
$ch = curl_init("https://pixdoc.dev/api/v1/screenshot");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode(["html" => "<h1>Hello World</h1>"]),
CURLOPT_RETURNTRANSFER => true,
]);
$png = curl_exec($ch);
file_put_contents("screenshot.png", $png);Pass a template_id and variables instead of raw HTML.
$ch = curl_init("https://pixdoc.dev/api/v1/pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"template_id" => "invoice",
"variables" => [
"company" => "Acme Corp",
"total" => "$1,250.00",
],
]),
CURLOPT_RETURNTRANSFER => true,
]);
$pdf = curl_exec($ch);
file_put_contents("invoice.pdf", $pdf);