I've used this package to generate invoices:
https://github.com/barryvdh/laravel-dompdf
It can generate an invoice from a HTML string. So I used a blade view to leverage Laravel features.
Just be aware that, due to dompdf limitations, not all CSS is exported correctly.
The code I had was basically this:
<?php
namespace App\Http\Controllers;
use App\Models\Order;
use Illuminate\Contracts\View\Factory;
class DownloadInvoiceController extends Controller
{
public function show(Factory $viewFactory, Order $order)
{
$html = $viewFactory->make('invoice.show', [
'order' => $order,
'contact' => $order->contact,
])->render();
/** @var \Barryvdh\DomPDF\PDF $pdf */
$pdf = \resolve('dompdf.wrapper');
$pdf->loadHtml($html);
return $pdf->download();
}
}
And I used a HTML table to make the invoice layout, just like the old days...
Hope this helps =)