PHP code example of baidouabdellah / laravel-arpdf
1. Go to this page and download the library: Download baidouabdellah/laravel-arpdf 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/ */
baidouabdellah / laravel-arpdf example snippets
use ArPDF;
public function invoice()
{
return ArPDF::direction('rtl')
->title('فاتورة')
->author('My Company')
->header('<div style="text-align:right">رأس الصفحة</div>')
->footer('<div style="text-align:center">{PAGENO}</div>')
->watermarkText('سري')
->loadView('pdf.invoice', ['title' => 'فاتورة'])
->download('invoice.pdf');
}
ArPDF::profile('invoice_ar')
->registerTemplate('invoice_basic', '<h1>{{ title }}</h1><p>{{ customer.name }}</p>')
->loadTemplate('invoice_basic', [
'title' => 'فاتورة',
'customer' => ['name' => 'أحمد'],
])
->useCache(true, 3600)
->download('invoice.pdf');
$pdf = app(\Baidouabdellah\LaravelArpdf\ArPDF::class);
$pdf->registerLayout('base', '<html><body>{{ section:header }}{{ content }}{{ component:footer }}</body></html>')
->registerComponent('footer', '<footer>{{ company }}</footer>')
->registerTemplate('invoice', \"@layout('base')\\n@section('header')<h1>{{ title }}</h1>@endsection\\n<p>{{ customer.name }}</p>\")
->loadTemplate('invoice', [
'title' => 'فاتورة',
'customer' => ['name' => 'أحمد'],
'components' => ['footer' => ['company' => 'My Co']],
]);
$pdf->report(function ($r) {
$r->heading('تقرير شهري')->table(['البند', 'القيمة'], [['المبيعات', 15000]]);
});
$pipeline = $pdf->queuePipeline(); // file-based queue
$jobId = $pipeline->enqueue($pdf, storage_path('app/reports/monthly.pdf'));
$pipeline->processNext();
$pdf->laravelQueuePipeline()->dispatchSync($pdf, storage_path('app/reports/sync.pdf'));
use Baidouabdellah\LaravelArpdf\Contracts\PdfPlugin;
class FooterPlugin implements PdfPlugin {
public function beforeRender($pdf, string $html, array $options): array {
return ['html' => $html . '<footer>Signed</footer>', 'options' => $options];
}
public function afterRender($pdf, string $binary, array $context): string {
return $binary;
}
}
$pdf->usePlugin(new FooterPlugin())->loadHTML('<h1>Doc</h1>');
$pdf->usePluginNamed('watermark_text', ['text' => 'CONFIDENTIAL', 'alpha' => 0.15])
->usePluginNamed('signature_block', ['signer' => 'Admin', 'title' => 'CTO'])
->usePluginNamed('quick_qr', ['text' => 'INV-1001', 'size' => 90]) // offline QR
->loadHTML('<h1>Invoice</h1>');
$pdf->usePluginNamed('certificate_signature', [
'private_key' => storage_path('keys/private.pem'),
'certificate' => storage_path('keys/cert.pem'),
'sidecar_path' => storage_path('app/signatures/invoice.sig.json'),
]);
$check = \Baidouabdellah\LaravelArpdf\ArPDF::verifySignature(
storage_path('app/invoices/invoice.pdf'),
storage_path('app/signatures/invoice.sig.json'),
storage_path('keys/cert.pem')
);
// Artisan command
// php artisan arpdf:verify-signature storage/app/invoices/invoice.pdf storage/app/signatures/invoice.sig.json --cert=storage/keys/cert.pem
$result = $pdf->assertSnapshot('doc-v1'); // stores/compares sha256 snapshot
if (! $result['matched']) {
// regression detected
}
bash
php artisan vendor:publish --provider="Baidouabdellah\LaravelArpdf\ArPDFServiceProvider"