Layout em Grid

Visao Geral

gpdf utiliza um sistema de grid de 12 colunas inspirado no Bootstrap. Cada linha e dividida em 12 colunas iguais, e voce especifica quantas colunas cada bloco de conteudo ocupa.

Configuracoes de Colunas

Largura Total (12 colunas)

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     │
└─────────────────────────────────────────────────┘

Duas Colunas Iguais (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 Colunas Iguais (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         │
└────────────────┴────────────────┴────────────────┘

Quatro Colunas Iguais (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)      │                                     │
└───────────┴─────────────────────────────────────┘

Artigo + Painel (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 Linha

Linhas com Altura Automatica

AutoRow ajusta sua altura para caber o conteudo:

page.AutoRow(func(r *template.RowBuilder) {
    r.Col(12, func(c *template.ColBuilder) {
        c.Text("This row's height is determined by its content")
    })
})

Linhas com Altura Fixa

Row recebe um 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                      │
└────────────────────────┴────────────────────────┘

Multiplo Conteudo em Colunas

Cada coluna pode conter multiplos elementos empilhados 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 │
└────────────────────────┴────────────────────────┘

Tamanhos de Pagina

ConstanteTamanhoDimensoes
document.A4A4210mm x 297mm
document.A3A3297mm x 420mm
document.LetterUS Letter8.5" x 11"
document.LegalUS Legal8.5" x 14"

Unidades

gpdf suporta multiplas unidades para dimensoes:

FuncaoUnidadeExemplo
document.Pt(v)Pontos (1/72 polegada)document.Pt(12)
document.Mm(v)Milimetrosdocument.Mm(20)
document.Cm(v)Centimetrosdocument.Cm(2.5)
document.In(v)Polegadasdocument.In(1)
document.Em(v)Relativo ao tamanho da fontedocument.Em(2)
document.Pct(v)Porcentagem do paidocument.Pct(50)

Margens Personalizadas

// 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),
})

Proximos Passos