PHP code example of pxlrbt / laravel-pdfable

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

    

pxlrbt / laravel-pdfable example snippets


BrowsershotDriver::configureUsing(
    fn (Browsershot $browser) => $browser->setCustomTempPath(storage_path('tmp'))
);

(new Invoice($order)->store()));

Route::get('/invoice/{order}', fn (Order $order) => new Invoice($order));

Route::get('/invoice/{order}', fn (Order $order) => (new Invoice($order)->stream()));

Route::get('/invoice/{order}', fn (Order $order) => (new Invoice($order)->download('custom-filename.pdf')));

return (new MailMessage)
    ->subject("Your Invoice")    
    ->attach(new Invoice($order));

dispatch(new Invoice($order));
// or
Invoice::dispatch($order);
// ...

class Invoice extends Pdfable
{
    public string $view = 'pdf.task';
}

public function page(): Page
{
    return Page::make()->size(PageSize::A4)->margins('narrow');
}

public function __construct(
    public Order $order,
    public ?Customer $customer = null,
)
{}

public function filename(): string
{
    return "customers/{$this->customer->id}/{$this->order->id}.pdf";
}
bash
php artisan vendor:publish --tag="pdfable-config"
bash
php artisan vendor:publish --tag="pdfable-views"
shell

php artisan make:pdf Invoice

html
<h1>Invoice for Order {{ $order->id }}</h1>

<div>Total: {{ $getTotal() }}</div>