Invoices, Quotes and Reports as Files
Last updated:
Generate in the background
Document generation is slow and it can fail. Doing it during a web request means a user waiting and a request that sometimes times out.
Queue it, generate it, store it, and notify when it is ready. For a single invoice that feels like overkill until the day someone generates four hundred.
Store, do not regenerate
An invoice regenerated next year may look different, because the template changed, the tax rate changed or a product name was edited. The document you sent is the record; store it.
- Store the generated file, not just the data
- Record which template version produced it
- Never overwrite a document that has been sent
- Keep them for as long as your records policy requires
Templates need to be maintainable
Someone in the business will want to change the wording, the logo or the layout. If that requires a developer every time, it will not happen and the documents will go stale.
HTML templates rendered to PDF are usually the right approach: familiar, editable, and version-controllable.
The details that matter
- Page breaks that do not split tables awkwardly
- Fonts embedded, so it renders the same everywhere
- Page numbers and continuation headers on multi-page documents
- Correct number formatting for currency and dates
- Accessible output where recipients need it
Test with real data
| Test case | Why |
|---|---|
| A very long customer name | Layout overflow |
| Fifty line items | Page breaks and totals |
| Zero line items | Empty state |
| A large currency amount | Number formatting |
| Accented characters | Font coverage |
Documents that look correct on the sample data and break on real data are the standard failure mode here.
Frequently asked questions
Which PDF library should we use?
Should invoices be regenerated on demand?
What about emailing them?
Can non-developers edit the templates?
Invoices generated by hand from a spreadsheet?
Generating them from your data is a contained piece of work with an immediate saving.
Related services
What we build for problems like this one