Invoice
Overview
The Invoice component generates a professional invoice PDF from structured data. No manual layout code needed — just provide the data and gpdf handles the formatting.
Usage
import "github.com/gpdf-dev/gpdf/template"
doc := template.Invoice(template.InvoiceData{
Number: "#INV-2026-001",
Date: "March 1, 2026",
DueDate: "March 31, 2026",
From: template.InvoiceParty{
Name: "ACME Corporation",
Address: []string{"123 Business Street", "Suite 100", "San Francisco, CA 94105"},
},
To: template.InvoiceParty{
Name: "John Smith",
Address: []string{"Tech Solutions Inc.", "456 Client Avenue", "New York, NY 10001"},
},
Items: []template.InvoiceItem{
{Description: "Web Development - Frontend", Quantity: "40 hrs", UnitPrice: 150.00, Amount: 6000.00},
{Description: "Web Development - Backend", Quantity: "60 hrs", UnitPrice: 150.00, Amount: 9000.00},
{Description: "UI/UX Design", Quantity: "20 hrs", UnitPrice: 120.00, Amount: 2400.00},
{Description: "Database Design", Quantity: "15 hrs", UnitPrice: 130.00, Amount: 1950.00},
{Description: "QA Testing", Quantity: "25 hrs", UnitPrice: 100.00, Amount: 2500.00},
{Description: "Project Management", Quantity: "10 hrs", UnitPrice: 140.00, Amount: 1400.00},
},
TaxRate: 10,
Currency: "$",
Payment: &template.InvoicePayment{
BankName: "First National Bank",
Account: "1234-5678-9012",
Routing: "021000021",
},
Notes: "Thank you for your business!",
})
data, err := doc.Generate()
┌─ A4 ──────────────────────────────────────────────┐
│ │
│ ACME Corporation INVOICE │
│ 123 Business Street #INV-2026-001 │
│ Suite 100 Date: March 1, 2026 │
│ San Francisco, CA 94105 Due: March 31, 2026 │
│ ──────────────────────────────────────────────── │
│ │
│ Bill To: Payment Info: │
│ John Smith First National Bank │
│ Tech Solutions Inc. Acct: 1234-5678-9012 │
│ 456 Client Avenue Routing: 021000021 │
│ New York, NY 10001 │
│ │
│ ┌──────────────┬────────┬──────────┬──────────┐ │
│ │ Description │ Qty │Unit Price│ Amount │ │
│ ├──────────────┼────────┼──────────┼──────────┤ │
│ │ Frontend │ 40 hrs │ $150.00 │$6,000.00 │ │
│ │ Backend │ 60 hrs │ $150.00 │$9,000.00 │ │
│ │ UI/UX Design │ 20 hrs │ $120.00 │$2,400.00 │ │
│ │ Database │ 15 hrs │ $130.00 │$1,950.00 │ │
│ │ QA Testing │ 25 hrs │ $100.00 │$2,500.00 │ │
│ │ PM │ 10 hrs │ $140.00 │$1,400.00 │ │
│ └──────────────┴────────┴──────────┴──────────┘ │
│ │
│ Subtotal: $23,250.00 │
│ Tax (10%): $2,325.00 │
│ ────────────────── │
│ Total: $25,575.00 │
│ │
│ ──────────────────────────────────────────────── │
│ Thank you for your business! │
│ │
└───────────────────────────────────────────────────┘
Data Types
InvoiceData
| Field | Type | Description |
|---|---|---|
Number | string | Invoice number |
Date | string | Invoice date |
DueDate | string | Payment due date |
From | InvoiceParty | Sender information |
To | InvoiceParty | Recipient information |
Items | []InvoiceItem | Line items |
TaxRate | float64 | Tax rate percentage (e.g., 10 for 10%) |
Currency | string | Currency symbol (e.g., "$", "EUR") |
Notes | string | Footer note |
Payment | *InvoicePayment | Optional payment information |
InvoiceParty
type InvoiceParty struct {
Name string
Address []string
}
InvoiceItem
type InvoiceItem struct {
Description string
Quantity string
UnitPrice float64
Amount float64
}
InvoicePayment
type InvoicePayment struct {
BankName string
Account string
Routing string
}
Customization
Pass document options to customize the invoice:
fontData, _ := os.ReadFile("fonts/NotoSansJP-Regular.ttf")
doc := template.Invoice(invoiceData,
template.WithFont("NotoSansJP", fontData),
template.WithDefaultFont("NotoSansJP", 12),
template.WithPageSize(document.Letter),
)
Using the Facade
The gpdf facade re-exports the Invoice constructor:
import "github.com/gpdf-dev/gpdf"
doc := gpdf.NewInvoice(invoiceData)