Diseno de cuadricula
Descripcion general
gpdf utiliza un sistema de cuadricula de 12 columnas inspirado en Bootstrap. Cada fila se divide en 12 columnas iguales, y usted especifica cuantas columnas abarca cada bloque de contenido.
Configuraciones de columnas
Ancho completo (12 columnas)
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 │
└─────────────────────────────────────────────────┘
Dos columnas iguales (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) │
└────────────────────────┴────────────────────────┘
Tres columnas iguales (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 │
└────────────────┴────────────────┴────────────────┘
Cuatro columnas iguales (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 │
└───────────┴───────────┴───────────┴───────────┘
Barra lateral + Principal (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) │ │
└───────────┴─────────────────────────────────────┘
Articulo + 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) │
└─────────────────────────────────┴───────────────┘
Tipos de fila
Filas con altura automatica
AutoRow ajusta su altura para adaptarse al contenido:
page.AutoRow(func(r *template.RowBuilder) {
r.Col(12, func(c *template.ColBuilder) {
c.Text("This row's height is determined by its content")
})
})
Filas con altura fija
Row toma un valor de altura explicito:
// 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 │
└────────────────────────┴────────────────────────┘
Multiples contenidos en columnas
Cada columna puede contener multiples elementos apilados verticalmente:
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 │
└────────────────────────┴────────────────────────┘
Tamanos de pagina
| Constante | Tamano | Dimensiones |
|---|---|---|
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" |
Unidades
gpdf soporta multiples unidades para dimensiones:
| Funcion | Unidad | Ejemplo |
|---|---|---|
document.Pt(v) | Puntos (1/72 pulgada) | document.Pt(12) |
document.Mm(v) | Milimetros | document.Mm(20) |
document.Cm(v) | Centimetros | document.Cm(2.5) |
document.In(v) | Pulgadas | document.In(1) |
document.Em(v) | Relativo al tamano de fuente | document.Em(2) |
document.Pct(v) | Porcentaje del padre | document.Pct(50) |
Margenes personalizados
// 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),
})
Siguientes pasos
- Estilos — Colores, decoracion de texto y tipografia
- Fuentes — Fuentes personalizadas y soporte CJK
- Encabezados y pies de pagina — Contenido a nivel de pagina