그리드 레이아웃
개요
gpdf는 Bootstrap에서 영감을 받은 12열 그리드 시스템을 사용합니다. 모든 행은 12개의 동일한 열로 나뉘며, 각 콘텐츠 블록이 차지하는 열 수를 지정합니다.
열 구성
전체 너비 (12열)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("Full width content", template.BgColor(pdf.RGBHex(0xE3F2FD)))
})
})
┌─────────────────────────────────────────────────┐
│ Full width content Col 12 │
└─────────────────────────────────────────────────┘
2등분 (6 + 6)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Col 6 (left)", template.BgColor(pdf.RGBHex(0xE8F5E9)))
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Col 6 (right)", template.BgColor(pdf.RGBHex(0xFFF3E0)))
})
})
┌────────────────────────┬────────────────────────┐
│ Col 6 (left) │ Col 6 (right) │
└────────────────────────┴────────────────────────┘
3등분 (4 + 4 + 4)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(4, func(c *template.ColBuilder) {
c.Text("Col 4", template.BgColor(pdf.RGBHex(0xFCE4EC)))
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("Col 4", template.BgColor(pdf.RGBHex(0xF3E5F5)))
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("Col 4", template.BgColor(pdf.RGBHex(0xE8EAF6)))
})
})
┌────────────────┬────────────────┬────────────────┐
│ Col 4 │ Col 4 │ Col 4 │
└────────────────┴────────────────┴────────────────┘
4등분 (3 + 3 + 3 + 3)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(3, func(c *template.ColBuilder) {
c.Text("Col 3", template.BgColor(pdf.RGBHex(0xE0F7FA)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Col 3", template.BgColor(pdf.RGBHex(0xE0F2F1)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Col 3", template.BgColor(pdf.RGBHex(0xFFF9C4)))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text("Col 3", template.BgColor(pdf.RGBHex(0xFFECB3)))
})
})
┌───────────┬───────────┬───────────┬───────────┐
│ Col 3 │ Col 3 │ Col 3 │ Col 3 │
└───────────┴───────────┴───────────┴───────────┘
사이드바 + 메인 (3 + 9)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(3, func(c *template.ColBuilder) {
c.Text("Sidebar (3)", template.BgColor(pdf.RGBHex(0xD7CCC8)))
})
r.Col(9, func(c *template.ColBuilder) {
c.Text("Main content (9)", template.BgColor(pdf.RGBHex(0xF5F5F5)))
})
})
┌───────────┬─────────────────────────────────────┐
│ Sidebar │ Main content (9) │
│ (3) │ │
└───────────┴─────────────────────────────────────┘
본문 + 패널 (8 + 4)
page.AutoRow(func(r *template.RowBuilder) {
r.Col(8, func(c *template.ColBuilder) {
c.Text("Article area (8)", template.BgColor(pdf.RGBHex(0xE1F5FE)))
})
r.Col(4, func(c *template.ColBuilder) {
c.Text("Side panel (4)", template.BgColor(pdf.RGBHex(0xFBE9E7)))
})
})
┌─────────────────────────────────┬───────────────┐
│ Article area (8) │ Side panel │
│ │ (4) │
└─────────────────────────────────┴───────────────┘
행 타입
자동 높이 행
AutoRow는 콘텐츠에 맞게 높이를 자동 조절합니다:
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("This row's height is determined by its content")
})
})
고정 높이 행
Row는 명시적인 높이 값을 사용합니다:
// 30mm 높이 행
page.Row(document.Mm(30), func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("This row is 30mm tall", template.BgColor(pdf.RGBHex(0xE3F2FD)))
})
})
// 50mm 높이 행 + 2열
page.Row(document.Mm(50), func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Left: 50mm row", template.BgColor(pdf.RGBHex(0xE8F5E9)))
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Right: 50mm row", template.BgColor(pdf.RGBHex(0xFFF3E0)))
})
})
┌─────────────────────────────────────────────────┐
│ This row is 30mm tall │
│ height: 30mm │
└─────────────────────────────────────────────────┘
┌────────────────────────┬────────────────────────┐
│ Left: 50mm row │ Right: 50mm row │
│ │ │
│ │ │
│ height: 50mm │
└────────────────────────┴────────────────────────┘
열 내 다중 콘텐츠
각 열은 수직으로 쌓이는 여러 요소를 포함할 수 있습니다:
page.AutoRow(func(r *template.RowBuilder) {
r.Col(6, func(c *template.ColBuilder) {
c.Text("Left column - line 1")
c.Text("Left column - line 2")
c.Text("Left column - line 3")
})
r.Col(6, func(c *template.ColBuilder) {
c.Text("Right column - line 1")
c.Text("Right column - line 2")
c.Text("Right column - line 3")
})
})
┌────────────────────────┬────────────────────────┐
│ Left column - line 1 │ Right column - line 1 │
│ Left column - line 2 │ Right column - line 2 │
│ Left column - line 3 │ Right column - line 3 │
└────────────────────────┴────────────────────────┘
페이지 크기
| 상수 | 크기 | 치수 |
|---|---|---|
document.A4 | A4 | 210mm x 297mm |
document.A3 | A3 | 297mm x 420mm |
document.Letter | US Letter | 8.5" x 11" |
document.Legal | US Legal | 8.5" x 14" |
단위
gpdf는 치수에 다양한 단위를 지원합니다:
| 함수 | 단위 | 예시 |
|---|---|---|
document.Pt(v) | 포인트 (1/72 인치) | document.Pt(12) |
document.Mm(v) | 밀리미터 | document.Mm(20) |
document.Cm(v) | 센티미터 | document.Cm(2.5) |
document.In(v) | 인치 | document.In(1) |
document.Em(v) | 폰트 크기 기준 | document.Em(2) |
document.Pct(v) | 부모 요소의 백분율 | document.Pct(50) |
사용자 정의 여백
// 균일한 여백
template.WithMargins(document.UniformEdges(document.Mm(20)))
// 면별 사용자 정의 여백
template.WithMargins(document.Edges{
Top: document.Mm(25),
Right: document.Mm(15),
Bottom: document.Mm(25),
Left: document.Mm(15),
})