Documentation
¶
Index ¶
- Constants
- Variables
- type Canvas
- type CellElement
- func (c *CellElement) AlignBottom() *CellElement
- func (c *CellElement) AlignCenter() *CellElement
- func (c *CellElement) AlignLeft() *CellElement
- func (c *CellElement) AlignMiddle() *CellElement
- func (c *CellElement) AlignRight() *CellElement
- func (c *CellElement) AlignTop() *CellElement
- func (c *CellElement) Background(col color.Color) *CellElement
- func (c *CellElement) Border(sides string, width float64, col color.Color) *CellElement
- func (c *CellElement) Padding(top, right, bottom, left float64) *CellElement
- func (c *CellElement) Span(cols, rows int) *CellElement
- type Document
- func (d *Document) AddHeader1(text string) *Document
- func (d *Document) AddHeader2(text string) *Document
- func (d *Document) AddHeader3(text string) *Document
- func (d *Document) AddImage(id ImageID) *ImageElement
- func (d *Document) AddPage() *Document
- func (d *Document) AddSeparator() *Document
- func (d *Document) AddSpace(units float64) *Document
- func (d *Document) AddTable() *TableBuilder
- func (d *Document) AddText(text string) *TextElement
- func (d *Document) AddTypeface(t Typeface) TypefaceID
- func (d *Document) ArcTo(x, y, rx, ry, angle, startAngle, endAngle float64)
- func (d *Document) CellFormat(w, h float64, txt, border string, ln int, align string, fill bool, link int, ...)
- func (d *Document) Circle(x, y, r float64, style string)
- func (d *Document) Draw() *Document
- func (d *Document) DrawPath(style string)
- func (d *Document) Err() error
- func (d *Document) GetMargins() (left, top, right, bottom float64)
- func (d *Document) GetPageSize() (width, height float64)
- func (d *Document) GetStringWidth(txt string) float64
- func (d *Document) GetX() float64
- func (d *Document) GetY() float64
- func (d *Document) Line(x1, y1, x2, y2 float64)
- func (d *Document) LineTo(x, y float64)
- func (d *Document) Log(message ...any)
- func (d *Document) MoveTo(x, y float64)
- func (d *Document) OutputTo(w io.Writer) error
- func (d *Document) Rect(x, y, w, h float64, style string)
- func (d *Document) RegisterImage(path string) (ImageID, error)
- func (d *Document) SetDrawColor(c color.Color)
- func (d *Document) SetDrawingFont(style string, size float64)
- func (d *Document) SetFillColor(c color.Color)
- func (d *Document) SetLineWidth(width float64)
- func (d *Document) SetLog(fn func(...any)) *Document
- func (d *Document) SetPageFooter() *PageFooter
- func (d *Document) SetPageHeader() *PageHeader
- func (d *Document) SetSize(pt float64) *Document
- func (d *Document) SetTextColor(c color.Color)
- func (d *Document) SetTheme(theme Theme) *Document
- func (d *Document) SetY(y float64)
- func (d *Document) SpaceBefore(u float64) *Document
- func (d *Document) Text(x, y float64, txt string)
- func (d *Document) Use(id TypefaceID) *Document
- func (d *Document) WritePdf(path string) error
- type Element
- type ImageElement
- func (i *ImageElement) AlignCenter() *ImageElement
- func (i *ImageElement) AlignLeft() *ImageElement
- func (i *ImageElement) AlignRight() *ImageElement
- func (i *ImageElement) Draw() *Document
- func (i *ImageElement) Height(mm float64) *ImageElement
- func (i *ImageElement) Width(mm float64) *ImageElement
- type ImageID
- type LineElement
- type Option
- type PageFooter
- type PageHeader
- type Style
- type TableBuilder
- func (t *TableBuilder) Background(c color.Color) *TableBuilder
- func (t *TableBuilder) BorderBottom(width float64, c color.Color) *TableBuilder
- func (t *TableBuilder) Cols(widths ...string) *TableBuilder
- func (t *TableBuilder) Draw() *Document
- func (t *TableBuilder) KeepTogether() *TableBuilder
- func (t *TableBuilder) Row(items ...any) *TableBuilder
- type TextElement
- func (t *TextElement) AlignCenter() *TextElement
- func (t *TextElement) AlignLeft() *TextElement
- func (t *TextElement) AlignRight() *TextElement
- func (t *TextElement) Bold() *TextElement
- func (t *TextElement) Color(c color.Color) *TextElement
- func (t *TextElement) Draw() *Document
- func (t *TextElement) Italic() *TextElement
- func (t *TextElement) Justify() *TextElement
- func (t *TextElement) Size(pt float64) *TextElement
- type Theme
- type ThemeMargin
- type ThemePage
- type Typeface
- type TypefaceID
Constants ¶
const ( FontBold = "B" FontItalic = "I" FontRegular = "" )
Variables ¶
var DefaultTheme = Theme{ Accent: "#1E3C78", Header: "#F0F4FA", Gray: "#646464", Body: "#000000", Sizes: struct { H1, H2, H3, Body, Small float64 }{ H1: 16, H2: 12, H3: 10, Body: 10, Small: 8, }, Spacing: struct { Paragraph, Section, Page float64 }{ Paragraph: 2, Section: 5, Page: 20, }, }
Functions ¶
This section is empty.
Types ¶
type Canvas ¶ added in v0.1.1
type Canvas interface {
GetX() float64
GetY() float64
SetY(y float64)
GetPageSize() (width, height float64)
GetMargins() (left, top, right, bottom float64)
SetLineWidth(width float64)
SetDrawColor(c color.Color)
SetFillColor(c color.Color)
SetTextColor(c color.Color)
Line(x1, y1, x2, y2 float64)
Rect(x, y, w, h float64, style string)
Circle(x, y, r float64, style string)
ArcTo(x, y, rx, ry, angle, startAngle, endAngle float64)
DrawPath(style string)
LineTo(x, y float64)
MoveTo(x, y float64)
Text(x, y float64, txt string)
GetStringWidth(txt string) float64
CellFormat(w, h float64, txt, border string, ln int, align string, fill bool, link int, linkStr string)
SetDrawingFont(style string, size float64)
}
Canvas defines the drawing surface interface used by external packages (such as tinywasm/chart) to render graphics on the PDF document.
type CellElement ¶ added in v0.0.39
type CellElement struct {
// contains filtered or unexported fields
}
Cell container.
func Cell ¶ added in v0.0.39
func Cell(children ...Element) *CellElement
func (*CellElement) AlignBottom ¶ added in v0.0.39
func (c *CellElement) AlignBottom() *CellElement
func (*CellElement) AlignCenter ¶ added in v0.0.39
func (c *CellElement) AlignCenter() *CellElement
func (*CellElement) AlignLeft ¶ added in v0.0.39
func (c *CellElement) AlignLeft() *CellElement
func (*CellElement) AlignMiddle ¶ added in v0.0.39
func (c *CellElement) AlignMiddle() *CellElement
func (*CellElement) AlignRight ¶ added in v0.0.39
func (c *CellElement) AlignRight() *CellElement
func (*CellElement) AlignTop ¶ added in v0.0.39
func (c *CellElement) AlignTop() *CellElement
func (*CellElement) Background ¶ added in v0.0.39
func (c *CellElement) Background(col color.Color) *CellElement
func (*CellElement) Border ¶ added in v0.0.39
func (c *CellElement) Border(sides string, width float64, col color.Color) *CellElement
func (*CellElement) Padding ¶ added in v0.0.39
func (c *CellElement) Padding(top, right, bottom, left float64) *CellElement
func (*CellElement) Span ¶ added in v0.0.39
func (c *CellElement) Span(cols, rows int) *CellElement
type Document ¶ added in v0.0.39
type Document struct {
// contains filtered or unexported fields
}
Document wraps the internal fpdf.Fpdf to provide a fluent API.
func NewDocument ¶ added in v0.0.39
NewDocument creates a new Document instance with UTF-8 support.
func (*Document) AddHeader1 ¶ added in v0.0.39
AddHeader1 adds a level 1 header.
func (*Document) AddHeader2 ¶ added in v0.0.39
AddHeader2 adds a level 2 header.
func (*Document) AddHeader3 ¶ added in v0.0.39
AddHeader3 adds a level 3 header.
func (*Document) AddImage ¶ added in v0.0.39
func (d *Document) AddImage(id ImageID) *ImageElement
AddImage adds an image by ID in flow mode.
func (*Document) AddSeparator ¶ added in v0.0.39
AddSeparator adds a horizontal line.
func (*Document) AddTable ¶ added in v0.0.39
func (d *Document) AddTable() *TableBuilder
func (*Document) AddText ¶ added in v0.0.39
func (d *Document) AddText(text string) *TextElement
AddText adds a text paragraph in flow mode.
func (*Document) AddTypeface ¶ added in v0.1.0
func (d *Document) AddTypeface(t Typeface) TypefaceID
func (*Document) CellFormat ¶ added in v0.1.1
func (*Document) Draw ¶ added in v0.0.39
Draw is a placeholder for consistency, though currently operations draw immediately.
func (*Document) GetMargins ¶ added in v0.1.1
func (*Document) GetPageSize ¶ added in v0.1.1
func (*Document) GetStringWidth ¶ added in v0.1.1
func (*Document) OutputTo ¶ added in v0.0.39
OutputTo writes the generated PDF into the provided writer.
func (*Document) RegisterImage ¶ added in v0.0.39
RegisterImage registers an image to be loaded immediately.
func (*Document) SetDrawColor ¶ added in v0.1.1
func (*Document) SetDrawingFont ¶ added in v0.1.1
SetDrawingFont activates the currently active typeface with the requested style and size. This satisfies the drawing interface constraint: the canvas does not expose SetFont(familyStr, ...), preventing untyped font family strings from being used in drawing contracts.
func (*Document) SetFillColor ¶ added in v0.1.1
func (*Document) SetLineWidth ¶ added in v0.1.1
func (*Document) SetPageFooter ¶ added in v0.0.39
func (d *Document) SetPageFooter() *PageFooter
func (*Document) SetPageHeader ¶ added in v0.0.39
func (d *Document) SetPageHeader() *PageHeader
func (*Document) SetTextColor ¶ added in v0.1.1
func (*Document) SetTheme ¶ added in v0.0.39
SetTheme sets the document theme. Missing numeric fields (Sizes, Spacing) inherit from DefaultTheme so callers can specify only the colors they care about without producing zero-height text.
func (*Document) SpaceBefore ¶ added in v0.0.39
SpaceBefore is an alias for AddSpace.
func (*Document) Use ¶ added in v0.1.0
func (d *Document) Use(id TypefaceID) *Document
type Element ¶ added in v0.0.39
type Element interface {
// contains filtered or unexported methods
}
Element is the interface for all layout components.
type ImageElement ¶ added in v0.0.39
type ImageElement struct {
// contains filtered or unexported fields
}
Image element.
func Image ¶ added in v0.0.39
func Image(id ImageID) *ImageElement
func (*ImageElement) AlignCenter ¶ added in v0.0.39
func (i *ImageElement) AlignCenter() *ImageElement
func (*ImageElement) AlignLeft ¶ added in v0.0.39
func (i *ImageElement) AlignLeft() *ImageElement
func (*ImageElement) AlignRight ¶ added in v0.0.39
func (i *ImageElement) AlignRight() *ImageElement
func (*ImageElement) Draw ¶ added in v0.0.39
func (i *ImageElement) Draw() *Document
Draw renders this image in flow mode. Requires the element to have been created via Document.AddImage. Returns the document for chaining.
func (*ImageElement) Height ¶ added in v0.0.39
func (i *ImageElement) Height(mm float64) *ImageElement
func (*ImageElement) Width ¶ added in v0.0.39
func (i *ImageElement) Width(mm float64) *ImageElement
type LineElement ¶ added in v0.0.39
type LineElement struct {
// contains filtered or unexported fields
}
Line element.
func Line ¶ added in v0.0.39
func Line() *LineElement
func (*LineElement) Color ¶ added in v0.0.39
func (l *LineElement) Color(c color.Color) *LineElement
func (*LineElement) Thickness ¶ added in v0.0.39
func (l *LineElement) Thickness(mm float64) *LineElement
func (*LineElement) Width ¶ added in v0.0.39
func (l *LineElement) Width(mm float64) *LineElement
type Option ¶ added in v0.0.39
type Option func(*Document)
func WithLogger ¶ added in v0.0.39
func WithMargins ¶ added in v0.0.39
func WithPageSize ¶ added in v0.0.39
type PageFooter ¶ added in v0.0.39
type PageFooter struct {
// contains filtered or unexported fields
}
func (*PageFooter) SetCenterText ¶ added in v0.0.39
func (pf *PageFooter) SetCenterText(t string) *PageFooter
func (*PageFooter) WithLeftRight ¶ added in v0.0.39
func (pf *PageFooter) WithLeftRight(leftText string) *PageFooter
func (*PageFooter) WithPageTotal ¶ added in v0.0.39
func (pf *PageFooter) WithPageTotal(align string) *PageFooter
type PageHeader ¶ added in v0.0.39
type PageHeader struct {
// contains filtered or unexported fields
}
func (*PageHeader) SetLeftText ¶ added in v0.0.39
func (ph *PageHeader) SetLeftText(t string) *PageHeader
func (*PageHeader) SetRightText ¶ added in v0.0.39
func (ph *PageHeader) SetRightText(t string) *PageHeader
type TableBuilder ¶ added in v0.0.39
type TableBuilder struct {
// contains filtered or unexported fields
}
func (*TableBuilder) Background ¶ added in v0.0.39
func (t *TableBuilder) Background(c color.Color) *TableBuilder
func (*TableBuilder) BorderBottom ¶ added in v0.0.39
func (t *TableBuilder) BorderBottom(width float64, c color.Color) *TableBuilder
func (*TableBuilder) Cols ¶ added in v0.0.39
func (t *TableBuilder) Cols(widths ...string) *TableBuilder
func (*TableBuilder) Draw ¶ added in v0.0.39
func (t *TableBuilder) Draw() *Document
func (*TableBuilder) KeepTogether ¶ added in v0.0.39
func (t *TableBuilder) KeepTogether() *TableBuilder
func (*TableBuilder) Row ¶ added in v0.0.39
func (t *TableBuilder) Row(items ...any) *TableBuilder
type TextElement ¶ added in v0.0.39
type TextElement struct {
// contains filtered or unexported fields
}
Text element represents a paragraph of text.
func Text ¶ added in v0.0.39
func Text(s string) *TextElement
func (*TextElement) AlignCenter ¶ added in v0.0.39
func (t *TextElement) AlignCenter() *TextElement
func (*TextElement) AlignLeft ¶ added in v0.0.39
func (t *TextElement) AlignLeft() *TextElement
func (*TextElement) AlignRight ¶ added in v0.0.39
func (t *TextElement) AlignRight() *TextElement
func (*TextElement) Bold ¶ added in v0.0.39
func (t *TextElement) Bold() *TextElement
func (*TextElement) Color ¶ added in v0.0.39
func (t *TextElement) Color(c color.Color) *TextElement
func (*TextElement) Draw ¶ added in v0.0.39
func (t *TextElement) Draw() *Document
Draw renders this text in flow mode. Requires the element to have been created via Document.AddText. Returns the document for chaining.
func (*TextElement) Italic ¶ added in v0.0.39
func (t *TextElement) Italic() *TextElement
func (*TextElement) Justify ¶ added in v0.0.39
func (t *TextElement) Justify() *TextElement
func (*TextElement) Size ¶ added in v0.0.39
func (t *TextElement) Size(pt float64) *TextElement
type Theme ¶ added in v0.0.39
type Theme struct {
Accent color.Color // color para texto de headers (H1, H2, H3)
Brand color.Color // color de marca para elementos decorativos (líneas, bandas)
Header color.Color
Gray color.Color
Body color.Color
Sizes struct {
H1, H2, H3, Body, Small float64
}
Spacing struct {
Paragraph, Section, Page float64
}
// Page size in mm. Zero values keep the fpdf default (A4).
Page ThemePage
// Margin in mm applied to all four sides. Zero values keep the default (20mm).
Margin ThemeMargin
}
type ThemeMargin ¶ added in v0.0.39
type ThemeMargin struct {
Top, Right, Bottom, Left float64
}
ThemeMargin defines the four page margins in millimetres.
type ThemePage ¶ added in v0.0.39
type ThemePage struct {
Width, Height float64
}
ThemePage defines the page dimensions in millimetres.
type Typeface ¶ added in v0.1.0
type Typeface struct {
// contains filtered or unexported fields
}
func LoadDeclared ¶ added in v0.1.1
func LoadDeclared(d font.Declaration) (Typeface, error)
LoadDeclared loads the four faces named by the font.Declaration. The .ttf extension is appended by this package.
type TypefaceID ¶ added in v0.1.0
type TypefaceID int