Skip to content

coenttb/swift-document-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

swift-document-templates

CI Development Status

A Swift package for data-driven generation of common business documents including invoices, letters, agendas, attendance lists, invitations, and signature pages.

Overview

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.

Features

  • 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

Installation

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")
        ]
    )
]

Quick Start

Invoice Example

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"
        ))
    ]
)

Invoice

Letter Example

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" }
}

Letter

Usage Examples

Agenda

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")
    ]
)

Agenda

Attendance List

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")
    ]
)

Attendance List

Invitation

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: [:]
)

Invitation

Signature Page

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: [:]
)

Signature Page

Generated Examples

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.

Platform Support

  • macOS 14.0+
  • iOS 17.0+
  • Mac Catalyst 17.0+

Related Packages

Dependencies

  • 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.

Third-Party Dependencies

License

This package is licensed under the Apache License, Version 2.0. See LICENSE for details.

Contributing

Contributions are welcome. Please open an issue to discuss significant changes before submitting a pull request.

Contact

For questions or feedback, reach out at [email protected] or visit coenttb.com.

Releases

No releases published

Sponsor this project

 

Languages