1. Go to this page and download the library: Download pdf-block/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pdf-block / laravel example snippets
use PdfBlock\Laravel\PdfBlockRenderer;
class ExportController extends Controller
{
public function pdf(Request $request, PdfBlockRenderer $renderer)
{
$document = $request->input('document');
return $renderer->toPdf($document)->toResponse('documento.pdf');
}
}
$renderer = app(PdfBlockRenderer::class);
// DSL → HTML (útil para debug, e-mail, preview)
$html = $renderer->toHtml($document);
// DSL → PDF
$pdf = $renderer->toPdf($document);
// Download (Content-Disposition: attachment)
return $pdf->toResponse('fatura.pdf');
// Preview inline no browser (Content-Disposition: inline)
return $pdf->toInlineResponse('preview.pdf');
// Salvar em disco
$pdf->save(storage_path('exports/fatura.pdf'));
// Conteúdo binário raw
$binary = $pdf->content();
// Tamanho em bytes
$bytes = $pdf->size();
// config/pdf-block.php
return [
// Driver ativo: 'local' ou 'browserless'
'driver' => env('PDF_BLOCK_DRIVER', 'local'),
'drivers' => [
'local' => [
'chrome_path' => env('PDF_BLOCK_CHROME_PATH', '/usr/bin/chromium'),
'timeout' => (int) env('PDF_BLOCK_TIMEOUT', 30),
'chrome_args' => [ /* defaults otimizados — ver config/pdf-block.php */ ],
],
'browserless' => [
'url' => env('PDF_BLOCK_BROWSERLESS_URL', 'http://browserless:3000'),
'token' => env('PDF_BLOCK_BROWSERLESS_TOKEN'),
'timeout' => (int) env('PDF_BLOCK_BROWSERLESS_TIMEOUT', 30),
'wait_until' => env('PDF_BLOCK_BROWSERLESS_WAIT_UNTIL', 'load'),
// Bloqueio de recursos no nível do Puppeteer — cancela requests
// ANTES de ir pra rede. Ganho de 200–800ms por PDF.
'reject_resource_types' => ['media', 'websocket', 'eventsource', 'manifest', 'texttrack', 'other'],
'reject_request_pattern' => ['google-analytics\\.com', 'googletagmanager\\.com', /* ... */],
],
],
'fonts' => [
'local_fonts' => [ /* 20 famílias corporativas — ver config/pdf-block.php */ ],
],
];
use PdfBlock\Laravel\Contracts\PdfDriver;
// AppServiceProvider::register()
$this->app->bind(PdfDriver::class, MyCustomDriver::class);