### Generate and return PDF in Laravel controller Source: https://spatie.be/docs/laravel-pdf/v1/basic-usage/responding-with-pdfs Creates a PDF response using a Blade view and returns it to be displayed in the browser. The PDF will be inlined by default. Requires the Spatie Laravel-pdf package and a corresponding Blade view template. The example shows generating an invoice PDF. ```php use function Spatie\LaravelPdf\Support\pdf; class DownloadInvoiceController { public function __invoke(Invoice $invoice) { return pdf() ->view('pdf.invoice', compact('invoice')) ->name('invoice-2023-04-10.pdf'); } } ``` -------------------------------- ### Return PDF as Response in Laravel Controller Source: https://spatie.be/docs/laravel-pdf/v1/introduction This code example shows how to return a generated PDF as a response from a Laravel controller method. It uses the Spatie Laravel PDF package to create a PDF from a Blade view and sets a specific filename for the download. This is useful for direct user downloads of generated documents. ```php use Spatie\LaravelPdf\Facades\Pdf; class DownloadInvoiceController { public function __invoke(Invoice $invoice) { return Pdf::view('pdfs.invoice', ['invoice' => $invoice]) ->format('a4') ->name('your-invoice.pdf'); } } ``` -------------------------------- ### Publish Laravel PDF Config File in Shell Source: https://spatie.be/docs/laravel-pdf/v1/advanced-usage/configuration Executes PHP Artisan command to publish the Laravel PDF configuration file to the app. Requires Laravel framework installation. Input: shell command. Output: copies config/laravel-pdf.php to app config directory. No known limitations. ```shell php artisan vendor:publish --tag=laravel-pdf-config ``` -------------------------------- ### Configure PDF Defaults in Laravel Service Provider Source: https://spatie.be/docs/laravel-pdf/v1/basic-usage/setting-defaults Shows how to set global default options for PDF generation using the Pdf facade in a service provider's boot method. These defaults apply to all PDFs but can be overridden when generating individual documents. The example configures a default header view and A3 format. ```php use Spatie\LaravelPdf\Facades\Pdf; use Spatie\LaravelPdf\Enums\Format; // in a service provider Pdf::default() ->headerView('pdf.header') ->format(Format::A3); ``` ```php // this PDF will use the defaults: it will be rendered in A3 format Pdf::html('
| Description | Quantity | Price | Total |
|---|---|---|---|
| Product 1 | 1 | $100.00 | $100.00 |
| Product 2 | 2 | $50.00 | $100.00 |
| Product 3 | 3 | $75.00 | $225.00 |