Grid Layout
Overview
gpdf uses a 12-column grid system inspired by Bootstrap. Every row is divided into 12 equal columns, and you specify how many columns each content block spans.
Column Configurations
Full Width (12 columns)
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 │
└─────────────────────────────────────────────────┘
Two Equal Columns (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) │
└────────────────────────┴────────────────────────┘
Three Equal Columns (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 │
└────────────────┴────────────────┴────────────────┘
Four Equal Columns (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 │
└───────────┴───────────┴───────────┴───────────┘
Sidebar + Main (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) │ │
└───────────┴─────────────────────────────────────┘
Article + Panel (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) │
└─────────────────────────────────┴───────────────┘
Row Types
Auto-Height Rows
AutoRow adjusts its height to fit the content:
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("This row's height is determined by its content")
})
})
Fixed-Height Rows
Row takes an explicit height value:
// 30mm tall row
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 tall row with two columns
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 │
└────────────────────────┴────────────────────────┘
Multiple Content in Columns
Each column can contain multiple elements stacked vertically:
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 │
└────────────────────────┴────────────────────────┘
Page Sizes
| Constant | Size | Dimensions |
|---|---|---|
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" |
Units
gpdf supports multiple units for dimensions:
| Function | Unit | Example |
|---|---|---|
document.Pt(v) | Points (1/72 inch) | document.Pt(12) |
document.Mm(v) | Millimeters | document.Mm(20) |
document.Cm(v) | Centimeters | document.Cm(2.5) |
document.In(v) | Inches | document.In(1) |
document.Em(v) | Relative to font size | document.Em(2) |
document.Pct(v) | Percentage of parent | document.Pct(50) |
Custom Margins
// Uniform margins
template.WithMargins(document.UniformEdges(document.Mm(20)))
// Custom margins per side
template.WithMargins(document.Edges{
Top: document.Mm(25),
Right: document.Mm(15),
Bottom: document.Mm(25),
Left: document.Mm(15),
})
Next Steps
- Styling — Colors, text decoration, and typography
- Fonts — Custom fonts and CJK support
- Headers & Footers — Page-level content