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',
    ];
}

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}) }}

<script type="text/php">
    if (isset($pdf)) {
        $size = 9;
        $color = [0,0,0];

        $font = $fontMetrics->getFont('Open Sans');
        $textHeight = $fontMetrics->getFontHeight($font, $size);
        $width = $fontMetrics->getTextWidth('Page 1 of 2', $font, $size);

        $foot = $pdf->open_object();

        $w = $pdf->get_width();
        $h = $pdf->get_height();

        $y = $h - $textHeight - 13;

        $pdf->close_object();
        $pdf->add_object($foot, 'all');

        $text = "Page {PAGE_NUM} of {PAGE_COUNT}";

        // Center the text
        $pdf->page_text($w / 2 - $width / 2, $y, $text, $font, $size, $color);
    }
</script>

php artisan dynamicpdf:demo

php artisan dynamicpdf:demo --disable