Documentation
¶
Overview ¶
Package builder provides a declarative, enterprise-grade API for generating PDF documents with GxPDF.
The builder uses a QuestPDF-inspired lambda composition pattern adapted for Go, with a 12-column grid layout system and automatic pagination.
Quick Start ¶
doc := builder.NewBuilder(
builder.WithPageSize(builder.A4),
builder.WithMargins(builder.Mm(20), builder.Mm(15), builder.Mm(20), builder.Mm(15)),
builder.WithTitle("My Document"),
)
doc.Page(func(page *builder.PageBuilder) {
page.Header(func(h *builder.Container) {
h.Text("Company Name", builder.Bold(), builder.FontSize(14))
h.Line()
})
page.Content(func(c *builder.Container) {
c.Row(func(r *builder.RowBuilder) {
r.Col(8, func(col *builder.ColBuilder) {
col.Text("Hello World", builder.Bold(), builder.FontSize(18))
})
r.Col(4, func(col *builder.ColBuilder) {
col.Text("Right column", builder.AlignRight())
})
})
c.Spacer(builder.Mm(5))
c.Text("This is a paragraph of text.")
})
page.Footer(func(f *builder.Container) {
f.Text(builder.PageNum+" / "+builder.TotalPages,
builder.AlignCenter(), builder.FontSize(8))
})
})
pdfBytes, err := doc.Build()
Architecture ¶
The builder package connects three layers:
- builder/ — user-facing API (this package)
- layout/ — pure computation layout engine (no PDF dependencies)
- creator/ — low-level PDF rendering backend
Users only import builder/ — all types (Value, Color, Size) are defined here. The layout/ package is an internal computation engine not intended for direct use.
Error Handling ¶
All errors are accumulated and returned as a joined error from Builder.Build. Layout definitions can be built without checking errors at each step.
Index ¶
- Constants
- Variables
- type Builder
- func (b *Builder) Build() ([]byte, error)
- func (b *Builder) BuildTo(w io.Writer) error
- func (b *Builder) BuildToFile(path string) error
- func (b *Builder) Bytes() ([]byte, error)
- func (b *Builder) Page(fn func(*PageBuilder))
- func (b *Builder) WriteTo(w io.Writer) (int64, error)
- func (b *Builder) WriteToFile(path string) error
- type CellBuilder
- type CellOption
- type ColBuilder
- type Color
- type Container
- func (c *Container) AutoRow(fn func(*RowBuilder))
- func (c *Container) EnsureSpace(height Value)
- func (c *Container) Image(data []byte, opts ...ImageOption)
- func (c *Container) KeepTogether(fn func(*Container))
- func (c *Container) Line(opts ...LineOption)
- func (c *Container) PageBreak()
- func (c *Container) PageNumber(format string, opts ...TextOption)
- func (c *Container) RichText(fn func(*RichTextBuilder), opts ...TextOption)
- func (c *Container) Row(fn func(*RowBuilder), opts ...RowOption)
- func (c *Container) Spacer(height Value)
- func (c *Container) Table(fn func(*TableBuilder))
- func (c *Container) Text(text string, opts ...TextOption)
- type ImageOption
- type LineOption
- type Option
- func WithAuthor(author string) Option
- func WithDefaultColor(color Color) Option
- func WithDefaultFontFamily(family string) Option
- func WithDefaultFontSize(size float64) Option
- func WithDefaultLineHeight(multiplier float64) Option
- func WithFont(family string, data []byte) Option
- func WithFontFile(family string, path string) Option
- func WithMargins(top, right, bottom, left Value) Option
- func WithPageSize(size Size) Option
- func WithTitle(title string) Option
- type PageBuilder
- type RichTextBuilder
- type RowBuilder
- type RowOption
- type Size
- type TableBuilder
- type TableRowBuilder
- type TableRowOption
- type TextOption
- func AlignCenter() TextOption
- func AlignJustify() TextOption
- func AlignLeft() TextOption
- func AlignRight() TextOption
- func BgColor(c Color) TextOption
- func Bold() TextOption
- func FontFamily(family string) TextOption
- func FontSize(size float64) TextOption
- func Italic() TextOption
- func LetterSpacing(pts float64) TextOption
- func LineHeight(multiplier float64) TextOption
- func Strikethrough() TextOption
- func TextColor(c Color) TextOption
- func Underline() TextOption
- type Value
Constants ¶
const ( // PageNum is replaced with the current page number after layout. PageNum = "\x00PAGE\x00" // TotalPages is replaced with the total page count after layout. TotalPages = "\x00TOTAL\x00" )
Page number placeholders for use with Container.PageNumber(). These must match layout.PageNumberPlaceholder / layout.TotalPagesPlaceholder.
Variables ¶
var ( // Black is opaque black (0, 0, 0). Black = Color{R: 0, G: 0, B: 0} // White is opaque white (1, 1, 1). White = Color{R: 1, G: 1, B: 1} // Red is pure red (1, 0, 0). Red = Color{R: 1, G: 0, B: 0} // Green is mid-tone green (0, 0.5, 0) — matches CSS "green". Green = Color{R: 0, G: 0.5, B: 0} // Blue is pure blue (0, 0, 1). Blue = Color{R: 0, G: 0, B: 1} Navy = Color{R: 0.102, G: 0.137, B: 0.494} // Gray is medium gray (0.5, 0.5, 0.5). Gray = Color{R: 0.5, G: 0.5, B: 0.5} // LightGray is near-white gray (#F5F5F5) — good for zebra-stripe backgrounds. LightGray = Color{R: 0.961, G: 0.961, B: 0.961} // DarkGray is dark gray (#555555). DarkGray = Color{R: 0.333, G: 0.333, B: 0.333} // Yellow is pure yellow (1, 1, 0). Yellow = Color{R: 1, G: 1, B: 0} // Orange is standard orange (1, 0.647, 0) — matches CSS "orange". Orange = Color{R: 1, G: 0.647, B: 0} // Purple is standard purple (0.5, 0, 0.5) — matches CSS "purple". Purple = Color{R: 0.5, G: 0, B: 0.5} // Cyan is pure cyan (0, 1, 1). Cyan = Color{R: 0, G: 1, B: 1} )
Predefined colors available for use in builder options. All components are in the [0, 1] range.
var ( A4 = Size{Width: 595.276, Height: 841.890} A3 = Size{Width: 841.890, Height: 1190.551} Letter = Size{Width: 612, Height: 792} Legal = Size{Width: 612, Height: 1008} )
Predefined page sizes.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is the document builder entry point. It accumulates page definitions and document-level configuration, then generates a PDF on Build().
Builder instances are not safe for concurrent use. Use one Builder per goroutine.
func NewBuilder ¶
NewBuilder creates a new Builder with the given document-level options. Sensible defaults are applied for any options not provided:
- Page size: A4
- Margins: 20mm top/bottom, 15mm left/right
- Default style: Helvetica 12pt, black text, 1.2 line height
Example:
b := builder.NewBuilder(
builder.WithPageSize(layout.PageLetter),
builder.WithFont("Inter", interTTF),
)
func (*Builder) Build ¶
Build runs the full PDF generation pipeline and returns the resulting PDF bytes. All accumulated errors (from font loading, invalid options, etc.) are returned as a joined error.
The pipeline:
- Check accumulated errors.
- Convert page definitions to layout.PageDef values.
- Run the paginator to produce positioned blocks.
- Walk the block tree with the renderer to emit PDF content via creator.
- Serialize to bytes and return.
func (*Builder) BuildTo ¶
BuildTo writes the generated PDF to the given io.Writer. Returns an error if PDF generation or writing fails.
func (*Builder) BuildToFile ¶
BuildToFile writes the generated PDF to the file at path, creating or truncating the file as needed.
func (*Builder) Bytes ¶
Bytes is an alias for Build() for callers that prefer the creator-style API.
func (*Builder) Page ¶
func (b *Builder) Page(fn func(*PageBuilder))
Page adds a page definition to the document. The fn callback receives a PageBuilder for defining header, content, and footer zones.
A single Page definition may produce multiple physical PDF pages if the content overflows — the paginator handles splitting automatically.
Example:
b.Page(func(p *builder.PageBuilder) {
p.Header(func(h *builder.Container) { h.Text("Header") })
p.Content(func(c *builder.Container) { c.Text("Body text") })
p.Footer(func(f *builder.Container) {
f.PageNumber(layout.PageNumberPlaceholder + " / " + layout.TotalPagesPlaceholder)
})
})
func (*Builder) WriteToFile ¶
WriteToFile is an alias for BuildToFile() for callers that prefer the creator-style API.
type CellBuilder ¶
type CellBuilder struct {
Container
}
CellBuilder is a Container that forms the content of a table cell. It embeds Container so all content methods (Text, Row, Image, Spacer, etc.) are available inside a cell.
type CellOption ¶
type CellOption func(*cellConfig)
CellOption is a functional option that configures a single table cell.
func CellBg ¶
func CellBg(c Color) CellOption
CellBg sets the background fill color for a single cell.
Example:
r.Cell(fn, builder.CellBg(builder.LightGray))
func CellBorder ¶
func CellBorder(c Color, width float64) CellOption
CellBorder sets a uniform border on all four sides of the cell.
Example:
r.Cell(fn, builder.CellBorder(builder.Gray, 0.5))
func CellPadding ¶
func CellPadding(v Value) CellOption
CellPadding sets uniform padding (all 4 sides) for a cell.
Example:
r.Cell(fn, builder.CellPadding(builder.Pt(6)))
func CellVAlignBottom ¶
func CellVAlignBottom() CellOption
CellVAlignBottom sets bottom vertical alignment for a cell's content.
func CellVAlignMiddle ¶
func CellVAlignMiddle() CellOption
CellVAlign sets the vertical alignment for a cell's content. Valid values: layout.VAlignTop (default), layout.VAlignMiddle, layout.VAlignBottom.
Example:
r.Cell(fn, builder.CellVAlignMiddle())
func CellVAlignTop ¶
func CellVAlignTop() CellOption
CellVAlignTop sets top vertical alignment for a cell's content (the default).
func ColSpan ¶
func ColSpan(n int) CellOption
ColSpan makes a cell span the given number of columns. Must be >= 1.
Example:
r.Cell(func(c *builder.CellBuilder) { c.Text("Total") }, builder.ColSpan(3))
func RowSpan ¶
func RowSpan(n int) CellOption
RowSpan makes a cell span the given number of rows. Must be >= 1.
Example:
r.Cell(func(c *builder.CellBuilder) { c.Text("Merged") }, builder.RowSpan(2))
type ColBuilder ¶
type ColBuilder struct {
// Container provides all content-adding methods.
Container
}
ColBuilder represents a single column cell in a 12-column grid row. It embeds Container, giving it the full set of content methods: Text, Row, AutoRow, Image, Line, Spacer, PageBreak, KeepTogether, EnsureSpace, and PageNumber.
ColBuilder instances are created by RowBuilder.Col and must not be constructed directly.
type Color ¶
type Color struct {
R, G, B float64 // 0.0 to 1.0
}
Color represents an RGB color.
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container is the universal content receiver. It collects layout elements that will be paginated and rendered. Container is used for page header, footer, and body content; it is also embedded in ColBuilder so that column cells support the same rich set of content methods.
All methods on Container accumulate layout.Element values into an internal slice. The slice is consumed by the Builder when constructing PageDef objects for the paginator.
func (*Container) AutoRow ¶
func (c *Container) AutoRow(fn func(*RowBuilder))
AutoRow is a convenience alias for Row with no options (auto height).
func (*Container) EnsureSpace ¶
EnsureSpace inserts a sentinel that ensures at least the given vertical space remains on the page. If less space is available, a page break is forced.
Example:
c.EnsureSpace(builder.Mm(50)) // push to next page if < 50mm remain
func (*Container) Image ¶
func (c *Container) Image(data []byte, opts ...ImageOption)
Image adds an image element to the container. The data parameter must be raw JPEG or PNG bytes.
Example:
c.Image(pngData, builder.FitWidth(layout.Mm(60)))
func (*Container) KeepTogether ¶
KeepTogether groups child elements so that they are never split across pages. If the group does not fit on the current page, it is pushed to the next page as a whole. If it does not fit on a fresh page, it is placed anyway.
Example:
c.KeepTogether(func(inner *builder.Container) {
inner.Text("Section Title", builder.Bold(), builder.FontSize(16))
inner.Text("This paragraph always follows the title.")
})
func (*Container) Line ¶
func (c *Container) Line(opts ...LineOption)
Line adds a horizontal rule (separator line) to the container.
Example:
c.Line(builder.LineColor(builder.Navy), builder.LineWidth(1))
func (*Container) PageBreak ¶
func (c *Container) PageBreak()
PageBreak inserts an explicit page break. Content after this point begins on a new page.
func (*Container) PageNumber ¶
func (c *Container) PageNumber(format string, opts ...TextOption)
PageNumber adds a page number element to the container. The format string should contain PageNum and/or TotalPages placeholders for substitution during the two-pass page number resolution.
Example:
c.PageNumber(builder.PageNum + " / " + builder.TotalPages,
builder.AlignRight(), builder.FontSize(8))
func (*Container) RichText ¶
func (c *Container) RichText(fn func(*RichTextBuilder), opts ...TextOption)
RichText adds a mixed-style inline text paragraph to the container. The fn callback receives a RichTextBuilder which is used to append individual spans with their own style overrides via RichTextBuilder.Span and hyperlinks via RichTextBuilder.Link.
Optional TextOption values in opts define the base style that all spans inherit unless they override it explicitly.
Example:
c.RichText(func(rt *builder.RichTextBuilder) {
rt.Span("Revenue grew ")
rt.Span("+18% ", builder.Bold(), builder.TextColor(builder.Hex("#1B7B34")))
rt.Span("year-over-year, driven by enterprise contract wins.")
}, builder.FontSize(10), builder.LineHeight(1.5), builder.AlignJustify())
func (*Container) Row ¶
func (c *Container) Row(fn func(*RowBuilder), opts ...RowOption)
Row adds a 12-column grid row to the container. The fn callback receives a RowBuilder which is used to define columns (each with a span 1-12).
Optional RowOption values configure the row height and background.
Example:
c.Row(func(r *builder.RowBuilder) {
r.Col(8, func(col *builder.ColBuilder) { col.Text("Left") })
r.Col(4, func(col *builder.ColBuilder) { col.Text("Right") })
})
func (*Container) Spacer ¶
Spacer adds a fixed-height vertical gap to the container.
Example:
c.Spacer(builder.Mm(10)) // 10mm gap
func (*Container) Table ¶
func (c *Container) Table(fn func(*TableBuilder))
Table adds a table to the container. The fn callback receives a TableBuilder for defining columns, header, body and footer rows.
Example:
c.Table(func(t *builder.TableBuilder) {
t.Columns(builder.Fr(1), builder.Fr(1), builder.Fr(1))
t.Header(func(h *builder.TableRowBuilder) {
h.Cell(func(c *builder.CellBuilder) { c.Text("Name", builder.Bold()) })
h.Cell(func(c *builder.CellBuilder) { c.Text("Value", builder.Bold()) })
h.Cell(func(c *builder.CellBuilder) { c.Text("Notes", builder.Bold()) })
}, builder.TableRowBg(builder.Navy), builder.CellTextColor(builder.White))
t.Row(func(r *builder.TableRowBuilder) {
r.Cell(func(c *builder.CellBuilder) { c.Text("Revenue") })
r.Cell(func(c *builder.CellBuilder) { c.Text("$4.2M") })
r.Cell(func(c *builder.CellBuilder) { c.Text("Q1 2026") })
})
})
func (*Container) Text ¶
func (c *Container) Text(text string, opts ...TextOption)
Text adds a single-style text paragraph to the container.
Example:
c.Text("Hello World")
c.Text("Important!", builder.Bold(), builder.FontSize(18), builder.TextColor(builder.Red))
type ImageOption ¶
type ImageOption func(*imageConfig)
ImageOption is a functional option for image elements.
func FitHeight ¶
func FitHeight(h Value) ImageOption
FitHeight constrains the image height to the given value, preserving aspect ratio.
func FitWidth ¶
func FitWidth(w Value) ImageOption
FitWidth constrains the image width to the given value, preserving aspect ratio.
type LineOption ¶
type LineOption func(*lineConfig)
LineOption is a functional option for horizontal rule elements.
func LineWidth ¶
func LineWidth(w float64) LineOption
LineWidth sets the stroke width of a horizontal rule in PDF points.
type Option ¶
type Option func(*config)
Option is a functional option that configures the document-level Builder.
func WithAuthor ¶
WithAuthor sets the PDF document author metadata.
func WithDefaultColor ¶
WithDefaultColor sets the default text color for all text elements.
func WithDefaultFontFamily ¶
WithDefaultFontFamily sets the default font family for all text elements. The family must have been registered via WithFont or WithFontFile.
func WithDefaultFontSize ¶
WithDefaultFontSize sets the default font size for all text elements.
func WithDefaultLineHeight ¶
WithDefaultLineHeight sets the default line height multiplier for all text elements.
func WithFont ¶
WithFont registers a TrueType font from raw bytes under the given family name. Once registered, the family name can be used with FontFamily() text option.
Example:
interTTF, _ := os.ReadFile("fonts/Inter-Regular.ttf")
builder.NewBuilder(builder.WithFont("Inter", interTTF))
func WithFontFile ¶
WithFontFile registers a TrueType font from a file path under the given family name.
Example:
builder.NewBuilder(builder.WithFontFile("Inter", "fonts/Inter-Regular.ttf"))
func WithMargins ¶
WithMargins sets the default page margins using Value units (pt, mm, cm, in).
Example:
builder.NewBuilder(builder.WithMargins(
builder.Mm(20), builder.Mm(15), builder.Mm(20), builder.Mm(15),
))
func WithPageSize ¶
WithPageSize sets the default page size for all pages in the document.
Example:
builder.NewBuilder(builder.WithPageSize(builder.Letter))
type PageBuilder ¶
type PageBuilder struct {
// contains filtered or unexported fields
}
PageBuilder constructs the structure of a single logical page. It provides three content zones — Header, Content, and Footer — each of which accepts a func(*Container) callback for adding elements.
A page definition generated by PageBuilder may span multiple physical pages if the content overflows; the paginator handles the overflow automatically.
PageBuilder instances are created by Builder.Page and must not be constructed directly.
func (*PageBuilder) Content ¶
func (p *PageBuilder) Content(fn func(*Container))
Content defines the main body content for this page. Long content that exceeds the available body area is automatically split across multiple physical pages.
Example:
page.Content(func(c *builder.Container) {
c.Text("Hello World")
c.Spacer(layout.Mm(5))
c.Text("Second paragraph")
})
func (*PageBuilder) Footer ¶
func (p *PageBuilder) Footer(fn func(*Container))
Footer defines the footer content for this page. The footer is rendered at the bottom of every physical page generated from this page definition.
Example:
page.Footer(func(f *builder.Container) {
f.PageNumber(
layout.PageNumberPlaceholder+" / "+layout.TotalPagesPlaceholder,
builder.AlignRight(), builder.FontSize(8),
)
})
func (*PageBuilder) Header ¶
func (p *PageBuilder) Header(fn func(*Container))
Header defines the header content for this page. The header is rendered at the top of every physical page generated from this page definition.
Example:
page.Header(func(h *builder.Container) {
h.Text("ACME Corp", builder.Bold(), builder.FontSize(14))
})
func (*PageBuilder) Margins ¶
func (p *PageBuilder) Margins(top, right, bottom, left Value)
Margins overrides the page margins for this page definition. When not called, the document-level defaults from WithMargins are used.
Example:
page.Margins(builder.Mm(25), builder.Mm(20), builder.Mm(25), builder.Mm(20))
func (*PageBuilder) Size ¶
func (p *PageBuilder) Size(s Size)
Size overrides the page size for this page definition. When not called, the document-level default from WithPageSize is used.
Example:
page.Size(builder.Letter)
type RichTextBuilder ¶
type RichTextBuilder struct {
// contains filtered or unexported fields
}
RichTextBuilder accumulates styled text spans that together form a single mixed-style paragraph. It is passed to the callback in Container.RichText.
Usage:
c.RichText(func(rt *builder.RichTextBuilder) {
rt.Span("Normal text ")
rt.Span("bold text ", builder.Bold())
rt.Span("red italic", builder.Italic(), builder.TextColor(builder.Red))
})
func (*RichTextBuilder) Link ¶
func (rt *RichTextBuilder) Link(text, url string, opts ...TextOption)
Link adds a hyperlink span. The text is rendered with underline and the link color (blue by default) unless overridden by opts. The url parameter sets the hyperlink target.
Example:
rt.Link("GxPDF repository", "https://github.com/coregx/gxpdf")
func (*RichTextBuilder) Span ¶
func (rt *RichTextBuilder) Span(text string, opts ...TextOption)
Span adds a styled text fragment to the paragraph. The opts are applied on top of the base style inherited from the Container.RichText call.
Example:
rt.Span("Important: ", builder.Bold(), builder.TextColor(builder.Red))
type RowBuilder ¶
type RowBuilder struct {
// contains filtered or unexported fields
}
RowBuilder constructs a single row in the 12-column grid. Columns are added via Col(span, fn), where span is a value from 1 to 12. All column spans in a row should sum to 12 for a full-width row; partial sums are valid and leave the remainder empty.
func (*RowBuilder) Col ¶
func (r *RowBuilder) Col(span int, fn func(*ColBuilder))
Col adds a column to the row.
span must be between 1 and 12 inclusive. Values outside this range are clamped. The fn callback receives a ColBuilder (which embeds Container) for adding text, images, nested rows, etc.
Example:
r.Col(8, func(c *builder.ColBuilder) { c.Text("Wide column") })
r.Col(4, func(c *builder.ColBuilder) { c.Text("Narrow column") })
type RowOption ¶
type RowOption func(*rowConfig)
RowOption is a functional option that modifies row configuration.
func RowPadding ¶
RowPadding sets uniform padding (all 4 sides) for a row. This adds space around the row content within the background area.
type TableBuilder ¶
type TableBuilder struct {
// contains filtered or unexported fields
}
TableBuilder is the fluent builder for a Table element. Use Container.Table to create one.
Example:
c.Table(func(t *builder.TableBuilder) {
t.Columns(builder.Fr(1), builder.Fr(2), builder.Pt(80))
t.Header(func(h *builder.TableRowBuilder) {
h.Cell(func(c *builder.CellBuilder) { c.Text("#", builder.Bold()) })
h.Cell(func(c *builder.CellBuilder) { c.Text("Item", builder.Bold()) })
h.Cell(func(c *builder.CellBuilder) { c.Text("Price", builder.Bold()) })
}, builder.RowBg(builder.Navy), builder.CellTextColor(builder.White))
t.Row(func(r *builder.TableRowBuilder) {
r.Cell(func(c *builder.CellBuilder) { c.Text("1") })
r.Cell(func(c *builder.CellBuilder) { c.Text("Widget") })
r.Cell(func(c *builder.CellBuilder) { c.Text("$9.99") })
})
})
func (*TableBuilder) Columns ¶
func (t *TableBuilder) Columns(defs ...Value)
Columns sets the column width definitions for the table. Each Value specifies how one column's width is computed:
- builder.Fr(1) — fractional share of available space
- builder.Pct(30) — 30% of available table width
- builder.Pt(80) — exactly 80 PDF points
- builder.Mm(25) — 25 millimeters
- builder.Auto() — content-driven (measured from cell text)
Example:
t.Columns(builder.Fr(1), builder.Fr(2), builder.Pt(80))
func (*TableBuilder) Footer ¶
func (t *TableBuilder) Footer(fn func(*TableRowBuilder), opts ...TableRowOption)
Footer adds a repeating footer row to the table. Footer rows are placed at the bottom of every page.
Example:
t.Footer(func(f *builder.TableRowBuilder) {
f.Cell(func(c *builder.CellBuilder) {
c.Text("Total", builder.Bold(), builder.AlignRight())
}, builder.ColSpan(2))
f.Cell(func(c *builder.CellBuilder) { c.Text("$99.00", builder.Bold()) })
})
func (*TableBuilder) Header ¶
func (t *TableBuilder) Header(fn func(*TableRowBuilder), opts ...TableRowOption)
Header adds a repeating header row to the table. Header rows are rendered at the top of every page when the table overflows. Row-level styling (background, text color) is applied via TableRowOption values.
Example:
t.Header(func(h *builder.TableRowBuilder) {
h.Cell(func(c *builder.CellBuilder) { c.Text("Name", builder.Bold()) })
h.Cell(func(c *builder.CellBuilder) { c.Text("Amount", builder.Bold()) })
}, builder.TableRowBg(builder.Navy), builder.CellTextColor(builder.White))
func (*TableBuilder) Row ¶
func (t *TableBuilder) Row(fn func(*TableRowBuilder), opts ...TableRowOption)
Row adds a body row to the table. Body rows form the main content and are split across pages on overflow.
Example:
t.Row(func(r *builder.TableRowBuilder) {
r.Cell(func(c *builder.CellBuilder) { c.Text("Alice") })
r.Cell(func(c *builder.CellBuilder) { c.Text("$42.00") })
}, builder.TableRowBg(builder.LightGray))
type TableRowBuilder ¶
type TableRowBuilder struct {
// contains filtered or unexported fields
}
TableRowBuilder collects cell definitions for a single table row.
func (*TableRowBuilder) Cell ¶
func (r *TableRowBuilder) Cell(fn func(*CellBuilder), opts ...CellOption)
Cell adds a cell to the row. The fn callback receives a CellBuilder (which embeds Container) for adding content. Cell-level options (ColSpan, RowSpan, CellPadding, CellBg, CellVAlign) are applied via CellOption values.
Example:
r.Cell(func(c *builder.CellBuilder) {
c.Text("Total", builder.Bold(), builder.AlignRight())
}, builder.ColSpan(3), builder.CellBg(builder.LightGray))
type TableRowOption ¶
type TableRowOption func(*tableRowConfig)
TableRowOption is a functional option that configures a table row.
func CellTextColor ¶
func CellTextColor(c Color) TableRowOption
CellTextColor sets the default text color inherited by all cells in a row. Individual cells may override this with their own TextOption.
func TableRowBg ¶
func TableRowBg(c Color) TableRowOption
TableRowBg sets the background color for a table row.
type TextOption ¶
type TextOption struct {
// contains filtered or unexported fields
}
TextOption configures text styling for elements like Container.Text and Container.PageNumber. Multiple options are composed left-to-right; later options override earlier ones.
Use constructor functions like Bold, FontSize, TextColor, AlignCenter to create options.
func AlignJustify ¶
func AlignJustify() TextOption
AlignJustify sets justified text alignment. The last line of a paragraph is left-aligned per typographic convention.
func BgColor ¶
func BgColor(c Color) TextOption
BgColor sets the background fill color of the text element's bounding box.
func FontFamily ¶
func FontFamily(family string) TextOption
FontFamily sets the font family by name (e.g. "Helvetica", "Inter"). The family must have been registered via WithFont or WithFontFile.
func LetterSpacing ¶
func LetterSpacing(pts float64) TextOption
LetterSpacing adds extra spacing between characters in PDF points.
func LineHeight ¶
func LineHeight(multiplier float64) TextOption
LineHeight sets the line height multiplier (relative to font size). A value of 1.2 means 20% leading — the default. 1.5 gives more open spacing.
func Strikethrough ¶
func Strikethrough() TextOption
Strikethrough adds a strikethrough decoration to the text.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a dimension with a unit. Use constructor functions Pt, Mm, Cm, In, Pct, Fr to create values.