PHP code example of mattsplat / declarative-pdf

1. Go to this page and download the library: Download mattsplat/declarative-pdf 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/ */

    

mattsplat / declarative-pdf example snippets


use Pdf\Document;
use Pdf\Style\StylePatch;
use Pdf\Style\TextAlign;

Document::create()
    ->meta(fn ($m) => $m->title('Report')->author('Jo'))
    ->page(fn ($p) => $p
        ->heading(1, 'Overview')
        ->paragraph('A paragraph that wraps automatically across lines.')
        ->paragraph('Justified body text.', new StylePatch(align: TextAlign::Justify)))
    ->save('out.pdf');
bash
composer install
composer check          # phpstan (level 6) + phpunit
composer test           # phpunit only
composer stan           # phpstan only

for f in examples/*.php; do php "$f"; done   # render every example
UPDATE_GOLDENS=1 composer test               # regenerate golden PDFs after an intended change
bash
php tools/makefont/makefont.php MyFont.ttf cp1252
# -> MyFont.json (+ MyFont.z); then:
#    $fonts->register('MyFont', FontFace::regular(), 'MyFont.json');

php tools/makefont/makefont.php MyFont.otf cp1252
# PostScript (CFF) outlines -> MyFont.json (+ MyFont.cff.z), embedded whole