Print invoices and delivery notes from Filament, exactly as previewed
It is the end of the month. The office has thirty invoices to send, and the warehouse needs a delivery note for each shipment. In many Filament apps this means a Blade view rendered to PDF: someone downloads it, opens it, finds that the 34th item row slipped off the bottom of page one, and asks a developer to change the view. When the bank account changes, the developer edits the view again.
This article shows the same invoices with Warp Print: a Print button on every invoice, a preview that shows the real pages, a template switch from invoice to delivery note, long tables that continue over pages, and many invoices in one print. All pictures are from the live demo.
The scene: a list of invoices with a Print button
The invoices are an ordinary Filament table. Each row has Print, Email and Edit. Above the table, Print list prints the list itself with its total.
Step 1: say what can be printed
The developer writes one small class, a PrintSource. It names the model and the fields a template may use. The demo's source has more fields (the customer's address, our bank account, tax per rate), but the shape is this:
use Qalainau\FilamentWarpPrint\Sources\Field;
use Qalainau\FilamentWarpPrint\Sources\PrintSource;
class InvoiceSource extends PrintSource
{
protected static string $model = Invoice::class;
public function fields(): array
{
return [
Field::text('number')->label('Invoice no.'),
Field::date('issued_on'),
Field::date('due_on'),
Field::text('customer.name')->label('Customer'),
Field::money('total', 'JPY')->state(fn (Invoice $invoice) => $invoice->total()),
Field::table('items', [
Field::text('name')->label('Item'),
Field::number('quantity'),
Field::money('unit_price', 'JPY'),
Field::money('amount', 'JPY')->state(fn (InvoiceItem $item) => $item->amount()),
])->label('Items'),
];
}
}
Register it with the plugin, and the panel gets a Print templates page. That is where the layout lives: an admin drags the fields, the logo and the item table onto an A4 page and presses Publish. No Blade view to edit when the bank account changes.
->plugin(WarpPrintPlugin::make()->sources([InvoiceSource::class]))
Step 2: the Print buttons
These are the actions of the demo's invoice table, unchanged:
->headerActions([
PrintTableAction::make()->totals(['total'])->groupBy(),
])
->recordActions([
PrintAction::make(),
EmailPrintAction::make(),
EditAction::make(),
])
->toolbarActions([
PrintBulkAction::make(),
EmailPrintBulkAction::make(),
])
Step 3: what you see is what prints
Press Print on an invoice. The window shows the real pages, with the page count under them. The preview is drawn by the same renderer as the printout, so the 16th row is where it will be on paper.
The warehouse does not need prices. Switch Template to the delivery note, and the same invoice is shown without amounts, with a barcode for scanning at the dock.
To offer only some templates on a button, name them: PrintAction::make()->templates(['invoice', 'delivery-note']).
Step 4: 80 rows over four pages
The real test of invoice printing is a long invoice. In the template, the item table is set to continue on the next page and to carry the total. Page 1 ends with "Carried forward", page 2 starts with "Brought forward" and a small continuation header.
If the last rows fit on a page but not above the totals box, Warp Print adds one more page for them. Nobody has to count rows.
Step 5: thirty invoices in one print
Tick the invoices and choose Print selected. Every invoice starts on a new page, in the order you ticked them, in one window and one print job.
Choose "Save as PDF" in the print dialog and the PDF has the same pages:
Other scenes
- Quotes and purchase orders from the same source, as other templates.
- Price tags and address labels with barcodes: label templates fill a sheet with many records.
- The Excel invoice your office already uses: upload it as an Excel template and Warp Print fills in the cells.
- "Original" and "Copy", or a PAID watermark, set in the template, not in code.
Limits worth knowing
- A PDF made on the server (for Download PDF and email attachments) needs Browsershot or Gotenberg. Without them, the browser's "Save as PDF" still works.
- One table per template flows over pages; other tables show the rows that fit in their box.
- The browser's print dialog may add its own header and footer (date, URL): turn them off in the dialog.
- Printing many records at once shows up to 200 in the window (
batch_limit); with more, the window offers to make the file in the background.
Try it
Open the invoices demo, press Print on any invoice and switch the template. Then open Print templates and move the logo, and print again. No sign-up, and the data is reset every hour.