스타일링
텍스트 옵션
모든 텍스트 스타일링은 c.Text()에 함수형 옵션을 통해 적용됩니다:
c.Text("Styled text",
template.FontSize(18),
template.Bold(),
template.TextColor(pdf.RGBHex(0x1A237E)),
)
사용 가능한 텍스트 옵션
| 옵션 | 설명 |
|---|---|
FontSize(size) | 폰트 크기 (포인트 단위, 기본값: 12) |
Bold() | 굵게 |
Italic() | 기울임꼴 |
FontFamily(name) | 등록된 폰트 패밀리 사용 |
TextColor(color) | 텍스트 전경 색상 |
BgColor(color) | 텍스트 배경 색상 |
AlignLeft() | 왼쪽 정렬 (기본값) |
AlignCenter() | 가운데 정렬 |
AlignRight() | 오른쪽 정렬 |
Underline() | 밑줄 장식 |
Strikethrough() | 취소선 장식 |
LetterSpacing(pts) | 문자 간 추가 간격 |
TextIndent(value) | 첫 줄 들여쓰기 |
색상
gpdf는 다양한 색상 모델을 지원합니다:
미리 정의된 색상
c.Text("Red", template.TextColor(pdf.Red))
c.Text("Green", template.TextColor(pdf.Green))
c.Text("Blue", template.TextColor(pdf.Blue))
c.Text("Yellow", template.TextColor(pdf.Yellow))
c.Text("Cyan", template.TextColor(pdf.Cyan))
c.Text("Magenta", template.TextColor(pdf.Magenta))
┌─────────────────────────────────────────┐
│ Red ← red │
│ Green ← green │
│ Blue ← blue │
│ Yellow ← yellow │
│ Cyan ← cyan │
│ Magenta ← magenta │
└─────────────────────────────────────────┘
| 상수 | 값 |
|---|---|
pdf.Black | Gray(0) |
pdf.White | Gray(1) |
pdf.Red | RGB(1, 0, 0) |
pdf.Green | RGB(0, 1, 0) |
pdf.Blue | RGB(0, 0, 1) |
pdf.Yellow | RGB(1, 1, 0) |
pdf.Cyan | RGB(0, 1, 1) |
pdf.Magenta | RGB(1, 0, 1) |
RGB 색상 (Float)
RGB 값의 범위는 0.0에서 1.0입니다:
c.Text("Orange", template.TextColor(pdf.RGB(1.0, 0.5, 0.0)))
c.Text("Purple", template.TextColor(pdf.RGB(0.5, 0.0, 0.5)))
c.Text("Teal", template.TextColor(pdf.RGB(0.0, 0.5, 0.5)))
Hex 색상
표준 hex 색상 코드를 사용합니다:
c.Text("Coral", template.TextColor(pdf.RGBHex(0xFF6B6B)))
c.Text("Turquoise", template.TextColor(pdf.RGBHex(0x4ECDC4)))
c.Text("Sky Blue", template.TextColor(pdf.RGBHex(0x45B7D1)))
c.Text("Sage", template.TextColor(pdf.RGBHex(0x96CEB4)))
그레이스케일
0.0 (검정)에서 1.0 (흰색) 범위의 값:
c.Text("Black", template.TextColor(pdf.Gray(0.0)))
c.Text("Dark gray", template.TextColor(pdf.Gray(0.3)))
c.Text("Medium gray", template.TextColor(pdf.Gray(0.5)))
c.Text("Light gray", template.TextColor(pdf.Gray(0.7)))
CMYK 색상
인쇄에 최적화된 출력을 위해:
c.Text("CMYK text", template.TextColor(pdf.CMYK(0, 1, 1, 0))) // Red in CMYK
배경 색상
BgColor()로 배경 색상 견본을 적용합니다:
page.AutoRow(func(r *template.RowBuilder) {
r.Col(3, func(c *template.ColBuilder) {
c.Text(" Red ", template.TextColor(pdf.White), template.BgColor(pdf.Red))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text(" Green ", template.TextColor(pdf.White), template.BgColor(pdf.Green))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text(" Blue ", template.TextColor(pdf.White), template.BgColor(pdf.Blue))
})
r.Col(3, func(c *template.ColBuilder) {
c.Text(" Yellow ", template.BgColor(pdf.Yellow))
})
})
┌───────────┬───────────┬───────────┬───────────┐
│ ██ Red ██ │ █ Green █ │ ██ Blue █ │ Yellow │
│ (white) │ (white) │ (white) │ (black) │
└───────────┴───────────┴───────────┴───────────┘
텍스트 장식
밑줄
c.Text("Underlined text for emphasis", template.Underline())
취소선
c.Text("Strikethrough text for deletions", template.Strikethrough())
장식 조합
c.Text("Combined underline and strikethrough",
template.Underline(), template.Strikethrough())
c.Text("Colored underlined text",
template.Underline(),
template.TextColor(pdf.RGBHex(0x1565C0)),
template.FontSize(14))
c.Text("Bold underlined heading",
template.Bold(), template.Underline(), template.FontSize(16))
┌─────────────────────────────────────────────┐
│ Normal text without decoration │
│ Underlined text for emphasis │ ← 밑줄
│ Strikethrough text for deletions │ ← 취소선
│ Combined underline and strikethrough │ ← 둘 다
│ Colored underlined text │ ← 파란색, 밑줄
│ Bold underlined heading │ ← 굵게, 밑줄
└─────────────────────────────────────────────┘
자간
문자 간격을 제어합니다:
c.Text("Normal spacing (default)")
c.Text("1pt letter spacing", template.LetterSpacing(1))
c.Text("3pt letter spacing", template.LetterSpacing(3))
c.Text("5pt letter spacing", template.LetterSpacing(5))
c.Text("Tight spacing (-0.5pt)", template.LetterSpacing(-0.5))
┌─────────────────────────────────────────────┐
│ Normal spacing (default) │
│ 1 p t l e t t e r s p a c i n g │ ← 약간 넓게
│ 3 p t l e t t e r s p a c i n g │ ← 더 넓게
│ 5 p t l e t t e r s p a c i n g │ ← 매우 넓게
│ Tight spacing (-0.5pt) │ ← 좁게
└─────────────────────────────────────────────┘
텍스트 들여쓰기
단락에 첫 줄 들여쓰기를 추가합니다:
c.Text("This paragraph has a 24pt first-line indent. "+
"The rest of the text wraps normally without indentation.",
template.TextIndent(document.Pt(24)))
c.Text("This paragraph has a larger 48pt indent. "+
"Useful for formal or academic document styling.",
template.TextIndent(document.Pt(48)))
┌─────────────────────────────────────────────┐
│ This paragraph has a 24pt first-line │
│ indent. The rest of the text wraps │
│ normally without indentation. │
│ │
│ This paragraph has a larger │
│ 48pt indent. Useful for formal or │
│ academic document styling. │
└─────────────────────────────────────────────┘