Build an invoice template

Build an invoice with DocStudio: seller and customer blocks, a line item table, calculated subtotal, tax and total, currency formatting and page numbers.

The invoice example is a complete template. This guide explains how it is built.

Layout

  1. A row with justify: "between" holds the seller block on one side and the invoice number and dates on the other.
  2. A divider separates the header from the bill-to block.
  3. A stack shows the customer.
  4. A table bound to lines lists the items.
  5. A stack at the end holds the payment terms.
  6. The page footer has a pageNumber with Page {n} of {total}.

Each row's amount is an expression, and the footer sums it:

{
  "id": "amount",
  "header": "Amount",
  "align": "end",
  "cell": {
    "fn": "format",
    "args": [
      "currency",
      { "fn": "mul", "args": [{ "path": "quantity" }, { "path": "unitPrice" }] },
      "USD"
    ]
  }
}
{
  "cells": [
    { "text": "Total due", "span": 3, "align": "end" },
    {
      "expr": {
        "fn": "format",
        "args": [
          "currency",
          {
            "fn": "mul",
            "args": [
              {
                "fn": "sum",
                "args": [{ "path": "$rows" }],
                "of": { "fn": "mul", "args": [{ "path": "quantity" }, { "path": "unitPrice" }] }
              },
              { "fn": "add", "args": [1, { "path": "invoice.taxRate" }] }
            ]
          },
          "USD"
        ]
      },
      "align": "end"
    }
  ]
}

Tips

  • Keep prices as numbers in your data and let the currency formatter present them.
  • Rounding: round rounds half away from zero. Round each line before summing if your accounting requires it.
  • Use repeatHeader: true and rowBreak: "avoid" so long invoices continue cleanly.
  • Set missingData to warn so a missing customer name is reported.

Output

Print it with printHtml, or produce a PDF with the server guide.

Last updated 2026-12-03