청구서
개요
Invoice 컴포넌트는 구조화된 데이터로부터 전문 청구서 PDF를 생성합니다. 수동 레이아웃 코드가 필요 없습니다 — 데이터만 제공하면 gpdf가 서식을 처리합니다.
사용법
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! │
│ │
└───────────────────────────────────────────────────┘
데이터 타입
InvoiceData
| 필드 | 타입 | 설명 |
|---|---|---|
Number | string | 청구서 번호 |
Date | string | 청구서 날짜 |
DueDate | string | 결제 기한 |
From | InvoiceParty | 발신자 정보 |
To | InvoiceParty | 수신자 정보 |
Items | []InvoiceItem | 항목 목록 |
TaxRate | float64 | 세율 (예: 10은 10%) |
Currency | string | 통화 기호 (예: "$", "EUR") |
Notes | string | 하단 메모 |
Payment | *InvoicePayment | 선택적 결제 정보 |
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
}
커스터마이징
문서 옵션을 전달하여 청구서를 커스터마이징합니다:
fontData, _ := os.ReadFile("fonts/NotoSansJP-Regular.ttf")
doc := template.Invoice(invoiceData,
template.WithFont("NotoSansJP", fontData),
template.WithDefaultFont("NotoSansJP", 12),
template.WithPageSize(document.Letter),
)
퍼사드 사용
gpdf 퍼사드는 Invoice 생성자를 재수출합니다:
import "github.com/gpdf-dev/gpdf"
doc := gpdf.NewInvoice(invoiceData)