PHP code example of daandekker / laravel-chrome-pdf

1. Go to this page and download the library: Download daandekker/laravel-chrome-pdf 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/ */

    

daandekker / laravel-chrome-pdf example snippets


// config/pdf.php
return [
    'chrome_path' => env('PDF_CHROME_PATH', '/usr/bin/chromium'),
    'timeout' => env('PDF_TIMEOUT', 60),
    'storage' => [
        'disk' => env('PDF_STORAGE_DISK', 'local'),
        'path' => env('PDF_STORAGE_PATH', 'pdfs'),
    ],
];

use DaanDekker\ChromePdf\Facades\Pdf;

// From a Blade view
$pdf = Pdf::view('pdf.invoice', ['order' => $order]);

// From HTML string
$pdf = Pdf::html('<h1>Hello World</h1>');

// Download as attachment
return Pdf::view('pdf.invoice', $data)->download('invoice.pdf');

// Display inline in browser
return Pdf::view('pdf.invoice', $data)->stream('invoice.pdf');

// Save to file path
Pdf::view('pdf.invoice', $data)->save(storage_path('app/invoices/invoice.pdf'));

// Save to Laravel storage disk
Pdf::view('pdf.invoice', $data)->store('invoices/invoice.pdf', 's3');

// Get raw PDF content
$content = Pdf::view('pdf.invoice', $data)->output();

Pdf::view('pdf.invoice', $data)
    ->format('A4')              // A4, A3, Letter, Legal, Tabloid
    ->orientation('portrait')   // portrait, landscape
    ->landscape()               // Shorthand for landscape
    ->portrait()                // Shorthand for portrait
    ->margins(10, 10, 10, 10)   // top, right, bottom, left (mm)
    ->margin(15)                // Uniform margins (mm)
    ->scale(1.0)                // Scale factor (0.1 - 2.0)
    ->printBackground(true)     // Include CSS backgrounds
    ->download('invoice.pdf');

Pdf::view('pdf.invoice', $data)
    ->header('<div style="font-size: 10px; text-align: center;">Company Name</div>')
    ->footer('<div style="font-size: 10px; text-align: center;">Page <span class="pageNumber"></span> of <span class="totalPages"></span></div>')
    ->download('invoice.pdf');

// Wait for JS to complete (useful for charts/graphs)
Pdf::view('pdf.report', $data)
    ->waitFor(2000)  // milliseconds
    ->download('report.pdf');

use DaanDekker\ChromePdf\Jobs\GeneratePdf;

GeneratePdf::dispatch(
    view: 'pdf.invoice',
    data: ['order' => $order],
    path: "invoices/order-{$order->id}.pdf",
    disk: 's3'  // optional, defaults to config value
);
bash
php artisan vendor:publish --tag=pdf-config