1. Go to this page and download the library: Download akira/laravel-pdf-invoices 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/ */
akira / laravel-pdf-invoices example snippets
use Akira\PdfInvoices\Builders\InvoiceBuilder;
use Akira\PdfInvoices\Builders\EntityBuilder;
use Akira\PdfInvoices\Builders\ItemBuilder;
$invoice = InvoiceBuilder::make()
->seller(
EntityBuilder::make()
->name('Your Company')
->address('123 Main St, City')
->email('[email protected]')
->vat('123456789')
->build()
)
->buyer(
EntityBuilder::make()
->name('Client Name')
->email('[email protected]')
->address('456 Oak Ave, Town')
->vat('987654321')
->build()
)
->addItem(
ItemBuilder::make()
->description('Professional Services')
->unitPrice(150)
->quantity(10)
->tax(0.19)
->build()
)
->addItem(
ItemBuilder::make()
->description('Support & Maintenance')
->unitPrice(100)
->quantity(5)
->tax(0.19)
->discount(0.10)
->build()
)
->locale('en')
->notes('Payment due within 30 days.')
->build();
// Generate and save PDF
$pdf = $invoice->generatePdf();
$pdf->save('invoices/invoice-001.pdf');
// Or get as stream (for downloads/email)
return response()->streamDownload(
fn() => echo $pdf,
'invoice-001.pdf'
);
// Use a specific template
$pdf = $invoice->generatePdf(template: 'branded');
// Portuguese invoice
$invoice = InvoiceBuilder::make()
->locale('pt')
// ... other methods
->build();
// French invoice
$invoice = InvoiceBuilder::make()
->locale('fr')
// ... other methods
->build();
// English invoice (default)
$invoice = InvoiceBuilder::make()
->locale('en')
// ... other methods
->build();
// Save to storage/app/invoices
$storage = app(\Akira\PdfInvoices\Contracts\StorageDriverContract::class);
$storage->save('invoice-001.pdf', $pdf);
// Or use Laravel Storage facade directly
\Illuminate\Support\Facades\Storage::put('invoices/invoice-001.pdf', $pdf);
// All of these work seamlessly:
$invoice->issuedAt(Carbon::now()); // Mutable Carbon
$invoice->issuedAt(now()); // CarbonImmutable (Laravel default)
$invoice->issuedAt(new DateTime('2024-01-01')); // DateTime
$invoice->issuedAt($model->created_at); // Eloquent model attribute (CarbonImmutable)
$invoice->getSubtotal(); // Sum of all items
$invoice->getTotalTax(); // Total tax amount
$invoice->getTotalDiscount(); // Total discount amount
$invoice->getTotal(); // Final amount due