PHP code example of ycchuang99 / laravel-pdf-chrome-driver

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

    

ycchuang99 / laravel-pdf-chrome-driver example snippets


'chrome-php' => [
    'chrome_path'               => env('LARAVEL_PDF_CHROME_PATH'),
    'no_sandbox'                => env('LARAVEL_PDF_NO_SANDBOX', false),
    'timeout'                   => env('LARAVEL_PDF_TIMEOUT', 30000),
    'startup_timeout'           => env('LARAVEL_PDF_STARTUP_TIMEOUT', 30),
    'window_size'               => null,
    'custom_flags'              => null,
    'user_data_dir'             => null,
    'env_variables'             => null,
    'ignore_certificate_errors' => env('LARAVEL_PDF_IGNORE_CERT_ERRORS', false),
    'send_sync_default_timeout' => env('LARAVEL_PDF_SEND_SYNC_DEFAULT_TIMEOUT'),
    'excluded_switches'         => null,
],

use Spatie\LaravelPdf\Facades\Pdf;

// Generate and save a PDF
Pdf::view('invoice', ['order' => $order])
    ->format('a4')
    ->save('/path/to/invoice.pdf');

// With all options
Pdf::html('<h1>Hello World</h1>')
    ->format('a4')
    ->landscape()
    ->margins(10, 10, 10, 10, 'mm')
    ->headerHtml('<div style="font-size:10px">Header</div>')
    ->footerHtml('<div style="font-size:10px">Page <span class="pageNumber"></span></div>')
    ->scale(0.9)
    ->save('/path/to/output.pdf');

// Use driver per-call (without changing default)
Pdf::view('invoice', $data)
    ->driver('chrome-php')
    ->save('/path/to/invoice.pdf');

// config/laravel-pdf.php
'chrome-php' => [
    'no_sandbox'     => true,
    'env_variables'  => ['HOME' => '/tmp', 'XDG_CONFIG_HOME' => '/tmp/.config'],
],
env
LARAVEL_PDF_DRIVER=chrome-php