Guides
HTML to PDF in PHP
Convert HTML templates to PDFs in PHP without installing heavy binaries. Simple REST API integration for Laravel, Symfony, or vanilla PHP.
Why avoid local PDF libraries in PHP?
DomPDF and TCPDF struggle with modern CSS and require complex font management. wkhtmltopdf is deprecated and inconsistent across platforms. A cloud-based HTML to PDF API eliminates these headaches and guarantees consistent rendering across all environments.
Rendering with cURL
render.php
$ch = curl_init("https://api.pdfapi.dev/v1/render");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json",
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"html" => "<h1>Hello {{name}}</h1>",
"data" => ["name" => "World"],
]));
$response = curl_exec($ch);
$result = json_decode($response, true);
echo "PDF URL: " . $result["url"];Integration with Laravel
In Laravel, wrap the API call in a service class and use it from your controllers or jobs. Queue the PDF generation for heavy workloads and store the resulting URL in your database for easy retrieval. Templates work great with Laravel's Blade syntax — design in Blade, render to HTML, then send to the API.
Next steps
- Read the full API documentation
- Create your free account