PHP code example of peptolab / php2pdf

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

    

peptolab / php2pdf example snippets


use Php2Pdf\Color\Rgb;
use Php2Pdf\Document\Document;
use Php2Pdf\Document\PageSize;
use Php2Pdf\Geometry\Box;

$doc = new Document('out.pdf');
$doc->info()->setTitle('Hello');

$page = $doc->addPage(PageSize::A4);
$page->setTrimBox(Box::fromMm(10, 10, 190, 277));

$page->canvas()
    ->setFillColor(Rgb::fromHex('#0088b8'))
    ->roundedRect(72, 72, 200, 100, 12)
    ->fill();

$doc->close();

$art = $doc->svg('artwork.svg', new NativeConverter(fallbackFont: $sans));
$page->place($art, Box::fromMm(20, 200, 80, 60), Fit::meet());

$table = $doc->table([Column::mm(55), Column::auto(), Column::mm(20, new CellStyle(alignment: Alignment::Right))], $base, 'body');
$table->addHeaderRow(['Reference', 'Project', 'Price'], new CellStyle(borderBottom: new Border(0.25)));
foreach ($entries as $entry) {
    $table->addRow([$entry->reference, $entry->name, sprintf('$%0.2f', $entry->price)]);
}
$doc->flow($table, Box::fromMm(15, 48, 180, 176), function (Document $doc, int $n) use ($template): Page {
    $page = $doc->addPage(PageSize::A4);
    $page->place($template, $page->mediaBox(), Fit::entire());

    return $page;
});