Skip to content

Customizing Invoice PDFs

FOSSBilling generates invoice PDFs with Dompdf, which renders HTML and CSS into a printable document.

Dompdf cannot fetch remote assets directly. Custom PDF templates must use local or embedded images, styles, and fonts. Use the supplied logo_source variable for the company logo and css for the invoice stylesheet instead of adding remote URLs.

FOSSBilling fetches remote company logos separately, blocking private networks and checking image types, contents, and dimensions. Downloads are limited to 2 MiB, and SVG logos must be self-contained. Unavailable or rejected remote logos are omitted from the PDF.

If a logo is missing, check that it is publicly reachable, uses a supported image format (PNG, JPEG, GIF, BMP, WebP, or self-contained SVG), and meets the size limits. Internal-only logo services cannot be used as remote sources. Generate a test PDF after changing the logo or custom assets.

Dompdf is not a complete PDF engine. FOSSBilling uses Dompdf 3.x, which supports many print-friendly CSS features but still has layout limitations:

SupportedNot Supported
CSS 2.1 and some CSS3Flexbox
@import, @media, @pageCSS Grid
CSS custom properties and math functions such as calc()Browser-style complex layouts
Basic positioning and table layoutsSplitting table rows or cells across pages
  1. Copy /modules/Invoice/templates/pdf/default-invoice.css
  2. Paste as /modules/Invoice/templates/pdf/custom-invoice.css

FOSSBilling automatically uses custom-invoice.css if it exists.

PDF layout with CSS classes

The default stylesheet uses these classes:

  • .CompanyLogo — Company logo image
  • .TopSectionDivider — Divider below the header area
  • .InvoiceInfo — Invoice number, dates, and status
  • .CompanyInfo — Seller/company heading and details
  • .ClientInfo — Client heading and details
  • .Breakdown — Line items, tax, discount, and total table
  • .InvoiceText — Custom invoice text blocks
  • .InvoiceFooter — Payment details, company footer, and signature
  • .muted-text — Muted footer signature text

Customize the HTML structure by adding a custom Twig template.

  1. Copy /modules/Invoice/templates/pdf/default-invoice.twig
  2. Paste as /modules/Invoice/templates/pdf/custom-invoice.twig

FOSSBilling uses custom-invoice.twig automatically.

Available in PDF templates:

VariableDescription
currency_codeInvoice currency code for format_currency.
cssContents of custom-invoice.css or default-invoice.css, inserted into the template's <style> block.
logo_sourceResolved company logo source: a local path, an image data URI (including validated remote logos), or an empty string. Dompdf does not fetch remote URLs.
sellerDisplay-ready seller/company lines keyed by labels such as Name, Address 1, Phone, and VAT Number.
seller_linesNumber of seller lines used by the default template for layout calculations.
footerCompany footer details, including company name, bank details, address fields, email, phone, VAT/company number, website, and signature.
buyerDisplay-ready buyer/client lines keyed by labels such as Company, Name, Address, City, Country, Phone, and VAT Number.
buyer_linesNumber of buyer lines used by the default template for layout calculations.
invoiceFull invoice API array. Line items are in invoice.lines; raw buyer, seller, and client data are in invoice.buyer, invoice.seller, and invoice.client.

The PDF renderer does not provide top-level client, company, or currency variables. Use invoice.client, seller/footer, and currency_code instead.

<div class="custom-header">
{% if logo_source %\}
<img src="{{ logo_source }}" alt="{{ seller['Name']|default(seller['Company']|default('Company logo'|trans)) }}">
{% endif %\}
<h1>{{ 'Invoice'|trans }} #{{ invoice.serie_nr }}</h1>
</div>

Remove backslashes in actual template code.

PDF templates support the same Twig filters available elsewhere in FOSSBilling:

{{ invoice.total|format_currency(currency_code) }} {# Format as currency #}
{{ invoice.created_at|format_date }} {# Format the invoice date #}
{{ invoice.text_1|default('')|markdown_to_html }} {# Render invoice text as HTML #}
  1. Make your edits to custom-invoice.css or custom-invoice.twig
  2. Generate a test invoice
  3. Download the PDF
  4. Review the output

For complex issues, enable FOSSBilling debug mode in config.php:

'debug_and_monitoring' => [
'debug' => true,
],

Then review your PHP or FOSSBilling logs for Dompdf-related messages.