PHP code example of renatio / dynamicpdf-plugin

1. Go to this page and download the library: Download renatio/dynamicpdf-plugin 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/ */

    

renatio / dynamicpdf-plugin example snippets


public function registerPDFTemplates()
{
    return [
        'renatio.demo::pdf.invoice',
        'renatio.demo::pdf.resume',
    ];
}

public function registerPDFLayouts()
{
    return [
        'renatio.demo::pdf.layouts.invoice',
        'renatio.demo::pdf.layouts.resume',
    ];
}

public function registerPDFVariables()
{
    return [
        'company' => 'Acme Ltd',
        'vat_rate' => fn () => Settings::get('vat_rate'),
    ];
}

Event::listen('renatio.dynamicpdf.beforeRender', function ($pdf, $model, array $data) {
    return ['watermark' => $data['order']->isDraft() ? 'DRAFT' : null];
});

php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"

return PDF::loadTemplate('renatio::invoice', ['file' => $file])
    ->setIsRemoteEnabled(true)
    ->stream();

{{ file.getPath }}

{{ file.getLocalPath }}

{{ file.getThumb(200, 200, {'crop' => true}) }}

$fake = PDF::fake();

$this->get('/backend/acme/orders/pdf/1');

$fake->assertRendered('acme::pdf.invoice', fn (array $data) => $data['order']->id === 1);
$fake->assertRenderedTimes('acme::pdf.invoice', 1);
$fake->assertNotRendered('acme::pdf.reminder');

php artisan dynamicpdf:demo

php artisan dynamicpdf:demo --disable