グリッドレイアウト

概要

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.A4A4210mm x 297mm
document.A3A3297mm x 420mm
document.LetterUS Letter8.5" x 11"
document.LegalUS Legal8.5" x 14"

単位

gpdfは寸法に複数の単位をサポートしています:

関数単位
document.Pt(v)ポイント (1/72 inch)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),
})

次のステップ