Appearance
Quick start with Laravel
Most HTML-to-PDF converters in PHP either have limited support for HTML, CSS, and JavaScript, or rely on wkhtmltopdf, which is no longer maintained. Doppio gives you a simpler alternative.
Learn how to send your first request with Laravel.
Render PDF
Using Doppio is simpler than maintaining a third-party package. In practice, all you need to do is send an HTTP request.
You can wrap the Doppio call in a service class:
php
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class PdfService
{
protected $apiEndpoint;
protected $authToken;
public function __construct()
{
$this->apiEndpoint = 'https://api.doppio.sh/v1/render/pdf/direct';
$this->authToken = env('DOPPIO_AUTH_TOKEN'); // set it in your .env file
}
public function createPdf($data)
{
// Send a request to the Doppio API
$response = Http::post($this->apiEndpoint, $data);
if ($response->successful()) {
return $response->body(); // or ->download('filename.pdf')
} else {
// Handle errors, for example by throwing an exception or returning a custom message
throw new \Exception('Failed to generate PDF: ' . $response->body());
}
}
}Then you can use the service like this:
php
$data = [
'page' => [
'pdf' => [
'printBackground' => 'true'
],
'goto' => [
'url' => 'https://your-url',
'options' => [
'waitUntil' => [
'networkidle0',
],
],
],
],
];
$pdf = $this->pdfService->createPdf($data);Check the synchronous and asynchronous methods to decide which one best fits your project.
Need more?
Looking for another framework? Explore our quick start guides by category.