KScript docs
EN

Documents: KScript.Document

Letters and invoices

Letter lays out a letter around the paragraphs inside it. In addresses, \n starts a new line:

<KScript.Document template="letter" to="'letter.pdf'">
  <Letter from="{'Life Lab\n12 Grid Street\nCambridge'}" to="{'Dr Ada Lovelace\nExample University'}" subject="Invitation to speak" opening="Dear Dr Lovelace," closing="Yours sincerely," signature="Alan Turing">
    <Paragraph>We would be delighted if you would give the opening talk.</Paragraph>
  </Letter>
</KScript.Document>
import KScript.Document

Document(template: letter, to: 'letter.pdf') {
  Letter(from: 'Life Lab\n12 Grid Street\nCambridge', to: 'Dr Ada Lovelace\nExample University', subject: 'Invitation to speak', opening: 'Dear Dr Lovelace,', closing: 'Yours sincerely,', signature: 'Alan Turing') {
    Paragraph "We would be delighted if you would give the opening talk."
  }
}

Invoice makes the whole invoice from a list of items. Each item has a description, a quantity (default 1) and a price, or an amount. The subtotal, tax and total are worked out for you:

<let name="items" value="[{ description: 'Consulting', quantity: 3, price: 450 }, { description: 'Travel', price: 64.2 }]" />

<import package="KScript.Document" />

<Document template="invoice" to="'invoice.pdf'">
  <Invoice number="INV-042" from="{'Life Lab Ltd\n12 Grid Street'}" to="Example University" due="20 December 2026" items="$items" currency="GBP" tax="20" notes="Please pay within 30 days." />
</Document>
$items = [{ description: 'Consulting', quantity: 3, price: 450 }, { description: 'Travel', price: 64.2 }]

import KScript.Document

Document(template: invoice, to: 'invoice.pdf') {
  Invoice(number: 'INV-042', from: 'Life Lab Ltd\n12 Grid Street', to: 'Example University', due: '20 December 2026', items: $items, currency: 'GBP', tax: 20, notes: 'Please pay within 30 days.')
}

currency: is a code such as GBP, USD, EUR or JPY, or any symbol. tax: is a percentage, tax_name: what it is called (default VAT), and paid: an amount already paid, which adds a balance due.