A Swift package for data-driven generation of common business documents including invoices, letters, agendas, attendance lists, invitations, and signature pages.
swift-document-templates provides type-safe Swift models and HTML-based rendering for business documents. Built on swift-html's DSL, it enables programmatic document generation with multi-language support via swift-translating, and PDF export capabilities through swift-html-to-pdf.
- Invoice: Generate invoices with line items, VAT calculations, and customizable metadata
- Letter: Create formal business letters with structured sender/recipient information
- Agenda: Build meeting agendas with topics, speakers, and timings
- Attendance List: Track attendees for meetings, events, or training sessions
- Invitation: Generate professional event invitations
- Signature Page: Create signature blocks for natural persons, legal entities, and complex organizational structures
- Multi-language support: Dutch and English translations built-in via swift-translating
- Type-safe HTML: All documents rendered using swift-html's compile-time-checked DSL
- PDF export: Direct conversion to PDF via swift-html-to-pdf integration
Add swift-document-templates to your package dependencies:
dependencies: [
.package(url: "https://github.com/coenttb/swift-document-templates.git", from: "0.1.0")
]Then add the product to your target:
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "DocumentTemplates", package: "swift-document-templates")
]
)
]import DocumentTemplates
let invoice = Invoice(
sender: .init(
name: "Your Company",
address: ["123 Main St", "City", "Country"],
phone: "123-456-7890",
email: "[email protected]",
website: "www.company.com",
kvk: "12345678",
btw: "NL123456789B01",
iban: "NL00BANK1234567890"
),
client: .init(
id: "CUST001",
name: "Client Name",
address: ["789 Maple St", "City", "Country"]
),
invoiceNumber: "INV001",
invoiceDate: Date.now,
expiryDate: (Date.now + 30.days),
metadata: [:],
rows: [
.service(.init(
amountOfHours: 160,
hourlyRate: 140.00,
vat: 21%,
description: "Consulting services"
))
]
)import DocumentTemplates
let sender: Letter.Sender = .init(
name: "Your Company",
address: ["123 Main St", "City", "Country"],
phone: "123-456-7890",
email: "[email protected]",
website: "www.company.com"
)
let recipient: Letter.Recipient = .init(
name: "Recipient Name",
address: ["456 Elm St", "City", "Country"]
)
let letter = Letter(
sender: sender,
recipient: recipient,
location: "Utrecht",
date: (sending: Date.now, signature: nil),
subject: "Subject of the Letter"
) {
"Dear \(recipient.name),"
p { "I hope this finds you well." }
p { "Best regards," }
p { "Your Name" }
}Create meeting agendas with topics:
import Agenda
let agenda = Agenda(
items: [
.init(title: "Opening Remarks"),
.init(title: "Q1 Financial Results"),
.init(title: "Strategic Planning Discussion")
]
)Track event participants:
import AttendanceList
let attendanceList = AttendanceList(
title: "Annual Conference",
metadata: [:],
attendees: [
.init(firstName: "John", lastName: "Doe", role: "Manager"),
.init(firstName: "Jane", lastName: "Smith", role: "Director")
]
)Generate event invitations:
import Invitation
let invitation = Invitation(
sender: .init(
name: "Your Company",
address: ["123 Main St", "City"],
phone: "123-456-7890",
email: "[email protected]",
website: "www.company.com"
),
recipient: .init(
id: "RECIP001",
name: "Guest Name",
address: ["456 Guest St", "City"]
),
invitationNumber: "INV-2024-001",
invitationDate: Date.now,
eventDate: Date.now,
location: "Conference Center",
metadata: [:]
)Create signature blocks with Signatory enum:
import SignaturePage
// Single individual
let individual = Signatory.individual(
name: "John Doe",
title: .init(dutch: "Directeur", english: "Director"),
metadata: [:]
)
// Group of signers
let group = Signatory(
name: .init(dutch: "Bedrijf B.V.", english: "Company B.V."),
signers: [
.init(name: .init("Jane Smith"), metadata: [:]),
.init(name: .init("Bob Johnson"), metadata: [:])
],
metadata: [:]
)All code examples shown in this README are automatically generated and tested as PDF documents to ensure they stay in sync with the codebase. The generated PDFs can be found in:
.github/Images/
These PDFs are regenerated on every test run (macOS only) by the README PDF Examples test suite, providing visual verification that the examples work as documented.
- macOS 14.0+
- iOS 17.0+
- Mac Catalyst 17.0+
- swift-html: The Swift library for domain-accurate and type-safe HTML & CSS.
- swift-html-to-pdf: The Swift package for printing HTML to PDF.
- swift-money: A Swift package with foundational types for currency and monetary calculations.
- swift-percent: A Swift package with foundational types for percentages.
- swift-translating: A Swift package for inline translations.
- swift-types-foundation: A Swift package bundling essential type-safe packages for domain modeling.
- pointfreeco/swift-dependencies: A dependency management library for controlling dependencies in Swift.
- apple/swift-collections: Commonly used data structures for Swift.
This package is licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributions are welcome. Please open an issue to discuss significant changes before submitting a pull request.
For questions or feedback, reach out at [email protected] or visit coenttb.com.





