PDF documents

How do I send a polished offer or invoice from a markdown file?

19 min readView as markdown17 chunks · 5.7k tokens in docspack

An offer or an invoice is a text file in git: the facts in YAML frontmatter, the covering letter in markdown. @getnarro/pdf turns it into a PDF with a letterhead, a logo, an address window, line items, VAT per rate and a footer on every page. You never type a total. You never repeat your own address, bank details or logo, because those live in one file the document pulls in.

Quick start

Scaffold a sample, edit it, print it. No Narro deck is involved; the commands are narro pdf.

npx @getnarro/cli pdf init invoice

npx @getnarro/cli pdf check invoice.md
npx @getnarro/cli pdf invoice.md

pdf init <invoice|offer> [dir] writes company.yaml, a placeholder logo.svg, a sample document and the schema mapping in .vscode/settings.json, merged into the file if you already have one. It refuses to overwrite an existing company.yaml, logo or sample. pdf check validates without starting a browser; pdf invoice.md writes invoice.pdf next to the input. Printing needs Chromium, the same browser narro export --pdf uses.

The commands

narro pdf <file> [-o, --out <file>] [--html] prints the document. --out picks another output path; --html also writes the standalone HTML next to it, which is the quickest way to debug a layout.

narro pdf check <file> loads, validates and computes. It prints every problem at once, each with the file it came from and the field path, and exits 1:

invoice.md › client.vatId: required when reverseCharge is true

When the document is valid it prints the net total, the VAT per rate and the gross total, and exits 0. Run it in CI or before every send.

A document

The frontmatter holds the data; the body is free GitHub-flavoured markdown. Everything that is not the document itself comes from extends:.

---
template: invoice
extends: ./company.yaml
number: RE-2026-0042
date: 2026-10-26
serviceDate: 2026-10-20
paymentTerms: 14
client:
  name: ACME GmbH
  address: [Musterstraße 1, 10115 Berlin]
items:
  - { description: Narro Pro licence, qty: 3, unit: Seat, price: 49.00, vat: 19 }
  - { description: Onboarding workshop, qty: 1, price: 800, vat: 19 }
discount: { percent: 5 }
---
Thank you for your order.

<!-- items -->

Payable within 14 days without deduction.

Without the <!-- items --> marker the whole body is printed above the items table and the totals. With it, the table and totals appear exactly there. The marker may appear once.

Raw HTML in the body is dropped, not rendered. A markdown image must be a local .svg, .png or .jpg file, and it is inlined; a remote image is rejected. The logo, the fonts and every image are embedded in the PDF, so it looks the same on every machine.

Render only documents you trust, never an untrusted upload. A document can reference any local file through extends, logo, css and body images, and any template module, which runs as code. The stylesheet named by css can also load remote resources through @import or url().

The shared sender file

Your name, address, tax IDs, bank, logo and theme belong in one company.yaml. Every document names it with extends:, and the file may extend another one in turn.

locale: de-DE
currency: EUR
logo: ./logo.svg
logoWidth: 38mm
sender:
  name: Narro GmbH
  address: [Beispielweg 5, 80331 München]
  vatId: DE999999999
bank:
  iban: DE02 1203 0000 0000 2020 51
theme:
  accent: "#4F46E5"
  font: Inter

The client’s country is printed in the address window only when it differs from yours, as DIN 5008 asks for mail abroad. Your country is sender.country, or else the region of locale, so de-DE makes it Germany.

How extends merges

A chain resolves depth first: later files override earlier ones, and the document overrides all of them. Objects merge key by key. Arrays and scalars replace, so items can never merge by accident. Paths in extends, logo, css and template resolve relative to the file that declares them, not to the document you print.

A cycle, a missing file or a YAML root that is not a mapping is an error that names the chain. Because every merged value remembers its file, a validation error tells you which file to fix. A document cannot currently unset an inherited value; to leave something out, leave it out of the shared file.

Company fields

These are the fields a company.yaml can set. A document can set any of them too.

FieldTypeRequiredDescription
localestring—BCP 47 locale for dates, numbers and labels. Default de-DE.
currencystring—ISO 4217 currency code. Default EUR.
paper"A4" | "Letter"—Paper size. Default A4.
letterhead"din5008-a" | "din5008-b" | "minimal"—Page layout: DIN 5008 form A or B, or a minimal letterhead. Default din5008-b.
logostring—Path to an svg, png or jpg logo, relative to the file declaring it
logoWidthstring—Printed logo width, e.g. 42mm
senderobject—Who sends the document
sender.namestring—Legal name of the sender
sender.addressstring[]—Address lines of the sender
sender.countrystring—Two-letter country code of the sender; defaults to the locale’s region (de-DE: DE)
sender.emailstring—Contact email, printed in the footer
sender.phonestring—Phone number, printed in the footer
sender.websitestring—Website, printed in the footer
sender.vatIdstring—VAT ID; an invoice needs this or taxNumber, and this under reverseCharge
sender.taxNumberstring—Tax number; an invoice needs this or vatId
sender.registerstring—Commercial register entry, e.g. Amtsgericht München, HRB 123456
sender.managingDirectorsstring[]—Managing directors, printed in the footer
bankobject—Bank details, printed in the footer
bank.namestring—Name of the bank
bank.ibanstringyes (if bank is set)IBAN payments go to
bank.bicstring—BIC of the bank
themeobject—Accent colour and font
theme.accentstring—Accent colour for headings, the table header rule and totals, as a hex colour. Default #4F46E5.
theme.font"Inter" | "Source Serif 4" | "IBM Plex Sans"—Bundled font family. Default Inter.
cssstring—Path to a stylesheet appended last, relative to the file declaring it

Items and computed totals

Each item has a description, a quantity, a net price and a VAT rate. Prices are read as exact decimals and held as integer cents: more than two decimals is a validation error. Quantities may be fractional, such as 1.5 hours, and a price may be negative for a credit.

The line total is the quantity times the price, rounded to the cent. A discount is a percentage or a fixed amount and applies to the net before VAT. It is spread over the VAT rates pro rata, so the VAT base stays correct for each rate; leftover cents go to the largest group. VAT is computed once per rate on the summed net of that rate, rounded half up. The gross total is the net, less the discount, plus the VAT. The due date is date plus paymentTerms days unless you give dueDate; an offer’s validDays works the same way. The grand total of an invoice may not be negative, and a fixed discount may not exceed the net total.

German rules

The invoice template checks the content §14 UStG requires, so a missing piece fails pdf check and not your client’s accountant. An invoice needs a number, a date, the sender’s name and address, the client’s name and address, a VAT ID or a tax number, a service date or a service period, and at least one item.

Two VAT modes change the document:

  • reverseCharge: true requires client.vatId and, on an invoice, sender.vatId (§14a UStG; a tax number is not enough). It requires every item’s VAT to be 0 and prints the reverse-charge note.
  • smallBusiness: true applies §19 UStG: every item’s VAT must be 0 and the note is printed.

Setting both is an error. With a German locale (de or de-DE) the VAT rate of an item must be 0, 7 or 19; other locales accept any rate from 0 to 100. An offer needs a number, a date, validUntil or validDays, the parties and at least one item; acceptance: true adds a signature and date block.

Layout and theme

letterhead chooses the page: din5008-a and din5008-b place the address window and the meta block at the DIN 5008 positions for form A or B, and minimal is a plain letterhead. paper is A4 or Letter; fold and punch marks print on A4 only. Page two onwards gets a slim header, and every page gets a three-column footer with address and contact, bank details, and tax IDs, register and directors, plus “Page X of Y”. Long item tables flow onto further pages with the header row repeated and no split rows.

theme.accent colours headings, the table header rule and the totals. theme.font is one of the bundled families, so nothing is fetched at print time. For anything else, point css at a stylesheet that is appended last; the theme is a layer of CSS custom properties you can override.

Invoice and offer fields

Both templates take the company fields above plus their own. This is the full list for an invoice.

FieldTypeRequiredDescription
localestring—BCP 47 locale for dates, numbers and labels. Default de-DE.
currencystring—ISO 4217 currency code. Default EUR.
paper"A4" | "Letter"—Paper size. Default A4.
letterhead"din5008-a" | "din5008-b" | "minimal"—Page layout: DIN 5008 form A or B, or a minimal letterhead. Default din5008-b.
logostring—Path to an svg, png or jpg logo, relative to the file declaring it
logoWidthstring—Printed logo width, e.g. 42mm
senderobjectyesWho sends the document
sender.namestringyesLegal name of the sender
sender.addressstring[]yesAddress lines of the sender
sender.countrystring—Two-letter country code of the sender; defaults to the locale’s region (de-DE: DE)
sender.emailstring—Contact email, printed in the footer
sender.phonestring—Phone number, printed in the footer
sender.websitestring—Website, printed in the footer
sender.vatIdstring—VAT ID; an invoice needs this or taxNumber, and this under reverseCharge
sender.taxNumberstring—Tax number; an invoice needs this or vatId
sender.registerstring—Commercial register entry, e.g. Amtsgericht München, HRB 123456
sender.managingDirectorsstring[]—Managing directors, printed in the footer
bankobject—Bank details, printed in the footer
bank.namestring—Name of the bank
bank.ibanstringyes (if bank is set)IBAN payments go to
bank.bicstring—BIC of the bank
themeobject—Accent colour and font
theme.accentstring—Accent colour for headings, the table header rule and totals, as a hex colour. Default #4F46E5.
theme.font"Inter" | "Source Serif 4" | "IBM Plex Sans"—Bundled font family. Default Inter.
cssstring—Path to a stylesheet appended last, relative to the file declaring it
templatestring—Built-in template name, or a path to a custom template module
numberstring | numberyesDocument number
datestring | dateyesDocument date, as YYYY-MM-DD
clientobjectyesWho the document is addressed to
client.namestringyesCompany or person name, the first line of the address window
client.contactstring—Contact person, printed under the name
client.addressstring[]yesAddress lines, at most five besides the name (contact included)
client.countrystring—Two-letter country code, printed when it differs from sender.country (or the locale’s region)
client.vatIdstring—The client’s VAT ID; required with reverseCharge
client.customerNumberstring | number—Your customer number for the client
itemsobject[]yesLine items; totals are computed from them
items[].descriptionstringyesWhat is being charged
items[].detailsstring—Extra lines under the description
items[].qtynumberyesQuantity; may be fractional, e.g. 1.5
items[].unitstring—Unit of the quantity, e.g. Std.
items[].pricenumber | stringyesNet price per unit, at most two decimals; negative for a credit
items[].vatnumberyesVAT rate in percent; for German locales 0, 7 or 19
discountobject—Discount applied to the net before VAT
discount.percentnumber—Percentage off the net total; give this or amount
discount.amountnumber | string—Fixed amount off the net total; give this or percent
reverseChargeboolean—Reverse charge: VAT 0 and the legal note; needs client.vatId. Default false.
smallBusinessboolean—Small-business rule (§ 19 UStG): VAT 0 and the legal note. Default false.
subjectstring—Subject line; defaults to the document type and number
serviceDatestring | date—Date of supply; an invoice needs this or servicePeriod
servicePeriodobject—Period of supply, from and to; an invoice needs this or serviceDate
servicePeriod.fromstring | dateyes (if servicePeriod is set)First day of the period
servicePeriod.tostring | dateyes (if servicePeriod is set)Last day of the period
paymentTermsinteger—Days after date until payment is due
dueDatestring | date—Due date, instead of paymentTerms

And for an offer.

FieldTypeRequiredDescription
localestring—BCP 47 locale for dates, numbers and labels. Default de-DE.
currencystring—ISO 4217 currency code. Default EUR.
paper"A4" | "Letter"—Paper size. Default A4.
letterhead"din5008-a" | "din5008-b" | "minimal"—Page layout: DIN 5008 form A or B, or a minimal letterhead. Default din5008-b.
logostring—Path to an svg, png or jpg logo, relative to the file declaring it
logoWidthstring—Printed logo width, e.g. 42mm
senderobjectyesWho sends the document
sender.namestringyesLegal name of the sender
sender.addressstring[]yesAddress lines of the sender
sender.countrystring—Two-letter country code of the sender; defaults to the locale’s region (de-DE: DE)
sender.emailstring—Contact email, printed in the footer
sender.phonestring—Phone number, printed in the footer
sender.websitestring—Website, printed in the footer
sender.vatIdstring—VAT ID; an invoice needs this or taxNumber, and this under reverseCharge
sender.taxNumberstring—Tax number; an invoice needs this or vatId
sender.registerstring—Commercial register entry, e.g. Amtsgericht München, HRB 123456
sender.managingDirectorsstring[]—Managing directors, printed in the footer
bankobject—Bank details, printed in the footer
bank.namestring—Name of the bank
bank.ibanstringyes (if bank is set)IBAN payments go to
bank.bicstring—BIC of the bank
themeobject—Accent colour and font
theme.accentstring—Accent colour for headings, the table header rule and totals, as a hex colour. Default #4F46E5.
theme.font"Inter" | "Source Serif 4" | "IBM Plex Sans"—Bundled font family. Default Inter.
cssstring—Path to a stylesheet appended last, relative to the file declaring it
templatestring—Built-in template name, or a path to a custom template module
numberstring | numberyesDocument number
datestring | dateyesDocument date, as YYYY-MM-DD
clientobjectyesWho the document is addressed to
client.namestringyesCompany or person name, the first line of the address window
client.contactstring—Contact person, printed under the name
client.addressstring[]yesAddress lines, at most five besides the name (contact included)
client.countrystring—Two-letter country code, printed when it differs from sender.country (or the locale’s region)
client.vatIdstring—The client’s VAT ID; required with reverseCharge
client.customerNumberstring | number—Your customer number for the client
itemsobject[]yesLine items; totals are computed from them
items[].descriptionstringyesWhat is being charged
items[].detailsstring—Extra lines under the description
items[].qtynumberyesQuantity; may be fractional, e.g. 1.5
items[].unitstring—Unit of the quantity, e.g. Std.
items[].pricenumber | stringyesNet price per unit, at most two decimals; negative for a credit
items[].vatnumberyesVAT rate in percent; for German locales 0, 7 or 19
discountobject—Discount applied to the net before VAT
discount.percentnumber—Percentage off the net total; give this or amount
discount.amountnumber | string—Fixed amount off the net total; give this or percent
reverseChargeboolean—Reverse charge: VAT 0 and the legal note; needs client.vatId. Default false.
smallBusinessboolean—Small-business rule (§ 19 UStG): VAT 0 and the legal note. Default false.
subjectstring—Subject line; defaults to the document type and number
validUntilstring | date—Last day the offer is valid; an offer needs this or validDays
validDaysinteger—Days after date the offer stays valid
acceptanceboolean—Adds a signature and date block for the client. Default false.

Custom templates

The built-in templates are invoice, offer. Set template: to a built-in name, or to the path of a local ES module whose default export comes from defineTemplate:

import { defineTemplate, ItemsTable, Letterhead, offerSchema } from "@getnarro/pdf";
import { createElement as h, Fragment } from "react";

export default defineTemplate({
  name: "quote",
  schema: offerSchema, // or your own zod schema built on the same fields
  title: ({ data }) => `Quote ${data.number}`,
  render: (ctx) =>
    h(
      Fragment,
      null,
      h(Letterhead, {
        ctx,
        documentTitle: `Quote ${ctx.data.number}`,
        meta: [["Quote", ctx.data.number]],
      }),
      h(ItemsTable, { ctx }),
    ),
  css: "",
});

Letterhead draws the first page, ItemsTable the items with their totals. The package also exports AddressWindow, MetaBlock, TotalsBlock and PageFooter, so a custom template keeps the letterhead and replaces only what differs. A custom template is trusted code: it runs in Node with your permissions when you print, so only point template: at files you wrote or reviewed.

Editor autocomplete

The JSON Schemas for company.yaml and each template ship in the package under schema/, generated from the validator itself so an editor cannot suggest a key pdf check rejects. pdf init writes a # yaml-language-server: $schema= comment into company.yaml and a .vscode/settings.json entry that maps the documents to the schemas, so completion and hover text work in VS Code with the YAML extension straight away.

From code

The same pipeline is a library. renderHtml(file) loads, validates and computes, and returns { html, title, paper, data, totals }. renderPdf(rendered, { browser }) prints that to PDF bytes; pass your own Playwright browser or let it launch Chromium.

import { writeFile } from "node:fs/promises";
import { renderHtml, renderPdf } from "@getnarro/pdf";

const rendered = await renderHtml("invoice.md");
await writeFile("invoice.pdf", await renderPdf(rendered));

renderPdf needs playwright-core, an optional peer dependency, and a Chromium it can find.

IntroductionWhat is Narro, and should I be writing markdown or React?
InstallationWhat do I install, and what does the project look like afterwards?
First deckWhat does a working React deck look like, end to end?
Markdown modeHow do I split a slide, style one word, or reveal a line — without leaving the markdown file?
Writing AI promptsWhat do I tell an AI so the deck it writes actually builds?
Rules for AI agentsWhat do I paste into my repo so an agent stops writing decks that build wrong?
React APIWhich component or hook do I import, and what does it take?
CLIWhich command do I run, and what are its flags?
Markdown APIHow do I read, edit, or validate a deck file from my own code instead of by hand?
Component referenceWhat props does this component take, and which package do I import it from?
Verifying a deckHow do I know my deck is actually correct?
AnimationHow do I reveal a list one line at a time, or move between slides with something other than a cut?
NavigationHow does the audience move through the deck, and how do I present it?
Canvas & positioningHow do I put something at an exact position instead of in the flow?
Images & mediaHow do I use an image as a background, tint it, or embed a video?
ArchitectureWhich package owns what, and why is the seam where it is?
Zooming canvasHow do I zoom and pan across one big canvas instead of cutting between slides?
Transform modeHow do I zoom and pan across one big canvas instead of cutting between slides?
Import & exportHow do I get this deck out as PPTX, PDF, or one file I can email?
VideoHow do I turn a story into a video, and keep it right when the words, the product or the source changes?
Recording a web appHow do I put a demo of my product in a deck or on a landing page without shipping a video of it?
Embedding a replayHow do I embed a recorded demo of my app in my React app, my Astro site, or any other page?
TerminalHow do I put a terminal demo in a deck, a README or a video, and find out when the tool it demonstrates stops saying what the demo says?
AI integrationHow do I wire an AI assistant up to Narro so it can write and build decks?
ThemingHow do I change the colours, fonts, and overall look of a deck?
Deck templatesHow do I define one house style with named layouts my slides can reference, like a PowerPoint master?
TroubleshootingSomething is wrong with my deck. What is it, and how do I fix it?
LimitationsWhat can't Narro do, and what do I do instead?
PDF documentsHow do I send a polished offer or invoice from a markdown file?
Explore your app as an agentHow does a coding agent check its own web UI change like a user would?
Study PDFsHow do I turn researched notes into a printable study sheet with formulas and index cards?