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
use Renatio\DynamicPDF\Classes\PDF;
return PDF::loadTemplate('acme.shop::pdf.invoice', ['number' => '2026/1'])->stream('invoice.pdf');
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) {
if ($model->code !== 'acme.shop::pdf.invoice' || ! isset($data['order'])) {
return;
}
return ['watermark' => $data['order']->isDraft() ? 'DRAFT' : null];
});
PDF::loadTemplate('renatio::invoice')
->setDpi(300)
->setOption(['defaultFont' => 'sans-serif'])
->stream();
return PDF::loadTemplate('renatio::invoice')
->save('/path-to/my_stored_file.pdf')
->stream();
return PDF::loadTemplate('renatio::invoice')
->setLogOutputFile(storage_path('temp/log.htm'))
->stream();
return PDF::loadTemplate('renatio::invoice', ['file' => $file])->stream();
return PDF::loadTemplate('renatio::invoice', ['file' => $file])
->setIsRemoteEnabled(true)
->setAllowedRemoteHosts(['cdn.example.com'])
->stream();
$order->invoice = PDF::loadTemplate('renatio::invoice', ['order' => $order])->toFile('invoice.pdf', public: false);
$order->save();
Mail::send('acme.shop::mail.invoice', $data, function ($message) use ($order) {
$message->to($order->email);
$message->attach(PDF::loadTemplate('acme.shop::pdf.invoice', ['order' => $order])->attachment('invoice.pdf'));
});
public function attachments(): array
{
return [PDF::loadTemplate('acme.shop::pdf.invoice', ['order' => $this->order])->attachment('invoice.pdf')];
}
PDF::loadTemplate('renatio::invoice')
->addInfo(['Title' => 'Invoice 2026/1', 'Author' => 'Acme'])
->save('invoices/2026-1.pdf', 's3');
return PDF::loadTemplate('renatio::invoice')->encrypt('reader-password', 'owner-password', ['print'])->stream();
public function onDownload()
{
return PDF::loadTemplate('renatio::invoice')->download('invoice.pdf');
}
use October\Rain\Exception\ForbiddenException;
use Renatio\DynamicPDF\Classes\PDF;
public function update_onDownloadInvoice($recordId)
{
if (! $this->user->hasAccess('acme.shop.orders.invoice')) {
throw new ForbiddenException;
}
$order = $this->formFindModelObject($recordId);
return PDF::loadTemplate('acme.shop::pdf.invoice', ['order' => $order], locale: $order->locale ?: null)
->download('invoice-' . str_slug(str_replace('/', '-', $order->number)) . '.pdf');
}
<?= Ui::ajaxButton(label: 'Download invoice', handler: 'onDownloadInvoice', class: 'btn-default')
use Renatio\DynamicPDF\Models\Template;
$html = PDF::parseTemplate(Template::byCode('acme.shop::pdf.invoice'), ['order' => $order]);
return PDF::loadTemplate('renatio::invoice')
->pageNumbers('Page {PAGE_NUM} of {PAGE_COUNT}', position: 'bottom-center', size: 9)
->stream();
$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');
use Renatio\DynamicPDF\Classes\PDF;
public function pdf()
{
return PDF::loadTemplate('renatio::invoice', ['name' => 'John Doe'])->stream('download.pdf');
}
return PDF::loadTemplate('renatio::invoice', $data, layout: 'renatio::layouts.company_b')->stream();
return PDF::loadTemplate('renatio::invoice', $data, locale: 'de')->download('rechnung.pdf');
'features' => [
'renatio_dynamicpdf_template' => true,
],
PDF::loadTemplate('acme.shop::pdf.invoice', $data, locale: 'pl')->download('faktura.pdf');
return PDF::loadTemplate('renatio::invoice')
->setPaper('a4', 'landscape')
->stream();
use Renatio\DynamicPDF\Classes\PDF;
function onStart()
{
return PDF::loadTemplate('renatio::invoice')->stream();
}
return PDF::loadTemplate('renatio::invoice')
->setIsFontSubsettingEnabled(true)
->stream();
bash
php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"
bash
php artisan dynamicpdf:render acme.shop::pdf.invoice --sample --output=invoice.pdf
php artisan dynamicpdf:render acme.shop::pdf.invoice [email protected] --locale=de --html
bash
php artisan dynamicpdf:export
php artisan dynamicpdf:export acme.shop::pdf.invoice acme.shop::pdf.quotation --path=pdf-templates.json
bash
php artisan dynamicpdf:demo
php artisan dynamicpdf:demo --disable