Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
PHP Development

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

  1. Page breaks that do not split tables awkwardly
  2. Fonts embedded, so it renders the same everywhere
  3. Page numbers and continuation headers on multi-page documents
  4. Correct number formatting for currency and dates
  5. Accessible output where recipients need it

Test with real data

Test caseWhy
A very long customer nameLayout overflow
Fifty line itemsPage breaks and totals
Zero line itemsEmpty state
A large currency amountNumber formatting
Accented charactersFont 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?

One that renders HTML and CSS well, so templates are maintainable. The specific choice matters less than that property.

Should invoices be regenerated on demand?

No. Store what was sent. Regeneration produces documents that differ from what the customer received.

What about emailing them?

Attach the stored file, and send through authenticated SMTP. Documents lost to spam filtering is a common and avoidable problem.

Can non-developers edit the templates?

With HTML templates, usually yes for wording and simple layout. That is worth designing for.

Keep reading

Invoices generated by hand from a spreadsheet?

Generating them from your data is a contained piece of work with an immediate saving.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Web DevelopmentCustom Software Development