Generate certificate PDFs in PHP
The simplest way to generate certificate PDFs in PHP is to POST a certificate HTML template plus a JSON data object to the Docweave API — no headless browser to install or run on your server.
Certificate template example
Any HTML works as a template. Use {{ placeholders }} for the recipient name, course or award title, issue date, and issuer:
<article style="font-family: 'Georgia', serif; text-align: center; padding: 64px; border: 8px solid #c9a227;">
<p style="letter-spacing: 4px; text-transform: uppercase; color: #6b6b6b;">Certificate of Completion</p>
<h1 style="font-size: 40px; margin: 16px 0;">{{ recipient_name }}</h1>
<p style="font-size: 18px; margin: 24px 0;">has successfully completed</p>
<h2 style="font-size: 28px; margin: 0 0 32px;">{{ course_title }}</h2>
<div style="display: flex; justify-content: space-between; margin-top: 48px; font-size: 14px; color: #444;">
<div>
<p style="border-top: 1px solid #444; padding-top: 8px;">{{ issue_date }}</p>
<p>Date issued</p>
</div>
<div>
<p style="border-top: 1px solid #444; padding-top: 8px;">{{ issuer_name }}</p>
<p>Issued by</p>
</div>
</div>
</article>Generate the certificate PDF from PHP
POST the template and per-recipient data to /api/v1/pdf with cURL, then write the raw response bytes straight to a file:
<?php
// Build the certificate payload: template + per-recipient data.
$payload = [
"source" => [
"type" => "template",
"template" => file_get_contents(__DIR__ . "/certificate-template.html"),
"data" => [
"recipient_name" => "Jordan Lee",
"course_title" => "Advanced PHP for Web APIs",
"issue_date" => "2026-07-14",
"issuer_name" => "Acme Training Academy",
],
],
"idempotencyKey" => "cert-jordan-lee-advanced-php",
];
$ch = curl_init("https://docweave.dev/api/v1/pdf");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer dw_live_your_key",
"Content-Type: application/json",
"Accept: application/pdf",
],
CURLOPT_RETURNTRANSFER => true,
]);
// The response body is the raw PDF bytes — write them straight to a file.
$pdfBytes = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($statusCode !== 200 || $pdfBytes === false) {
throw new RuntimeException("Certificate PDF generation failed with status {$statusCode}");
}
file_put_contents(__DIR__ . "/certificate.pdf", $pdfBytes);…or from an AI agent
An AI agent can generate the same certificate PDF via the Docweave MCP server, without writing any PHP or HTTP code at all — install it with npx @docweave/mcp and call the generate_pdf tool:
npx @docweave/mcp
// Then, from an AI agent, no HTTP plumbing:
generate_pdf({
source: {
type: "template",
template: "<article>...{{ recipient_name }}...{{ course_title }}...</article>",
data: {
recipient_name: "Jordan Lee",
course_title: "Advanced PHP for Web APIs",
issue_date: "2026-07-14",
issuer_name: "Acme Training Academy"
}
},
outputPath: "/tmp/certificate.pdf"
})FAQ
How do I generate a certificate PDF in PHP?
Send a POST request from PHP (with cURL or any HTTP client) to /api/v1/pdf, with a source of type "template" containing your certificate HTML and a data object with the recipient name, course or award title, issue date, and issuer. Docweave binds the JSON into the {{ placeholders }} and returns the finished certificate PDF as the raw response body.
Do I need to install a headless browser on my PHP server?
No. Docweave runs Chromium on its own infrastructure and renders the certificate remotely. Your PHP code only needs an HTTP client (cURL, Guzzle, etc.) — there is nothing to install, keep updated, or manage locally.
How do I avoid issuing a duplicate certificate PDF?
Pass an idempotencyKey with each request, such as a recipient-and-course ID. A repeat request with the same key returns the previously generated certificate instead of re-rendering or re-billing, which makes retries from PHP safe.
How is certificate PDF generation priced?
Pricing is per document, not per page. A single-page certificate costs the same as any other document, regardless of how much detail or how many placeholders the template contains.
Ready to generate certificate PDFs in production?
Get an API key