Documentation
¶
Index ¶
- Constants
- func CreateRingLogoTemplate(pdf *gofpdf.Fpdf, r, cx, cy float64) gofpdf.Template
- func CreateRingLogoTemplateWithLayers(pdf *gofpdf.Fpdf, r, cx, cy float64, renderBg, renderFg bool) gofpdf.Template
- func ExtractRunningFooterElement(elements []pdfdom.PDFElementNode, name string) (matchedName string, elem pdfdom.PDFElementNode, ...)
- func RenderDocTemplateFlow(l *LayoutPDF, elements []pdfdom.PDFElementNode) error
- func RenderDocTemplateOverlay(l *LayoutPDF, elements []pdfdom.PDFElementNode) error
- func RenderLogoPDF(outputPath string, pageWidth, pageHeight, x, y, r float64, ...) error
- func ShouldBreakPageAfter(node pdfdom.PDFElementNode) bool
- func ShouldBreakPageBefore(node pdfdom.PDFElementNode) bool
- type CellDef
- type CellFormatter
- type ColumnDef
- type ElemBr
- type ElemImg
- type FontGlyphRegistry
- type FontRegistration
- type ImageLoader
- type ImageResource
- type LayoutOptions
- type LayoutPDF
- func (l *LayoutPDF) BeginPage(page int) error
- func (l *LayoutPDF) CellDefFromTableCell(cellElem pdfdom.PDFElementNode, isHeader bool) CellDef
- func (l *LayoutPDF) CurrentFlowBottom() float64
- func (l *LayoutPDF) CurrentFlowBox() (x, y, width float64)
- func (l *LayoutPDF) EnsureTotalPagesAtLeast(n int)
- func (l *LayoutPDF) NextFlowPage() error
- func (l *LayoutPDF) PageTemplateData(pageNumber, pageTotal int) map[string]any
- func (l *LayoutPDF) RenderCreateTemplateElement(elem *pdfdom.ElemCreateTemplate) error
- func (l *LayoutPDF) RenderFinalFlowPageNums()
- func (l *LayoutPDF) RenderPageNum(page, pageCount int)
- func (l *LayoutPDF) RenderUseTemplateElement(elem *pdfdom.ElemUseTemplate, fallbackX, fallbackY float64) (renderedHeight float64, absolute bool, err error)
- func (l *LayoutPDF) ResolveFlowPlacement(node pdfdom.PDFElementNode, flowX, flowY, flowW float64) (x, y, width float64, absolute bool)
- func (l *LayoutPDF) ResolvePDFTextNode(node *pdfdom.PDFTextNode) string
- func (l *LayoutPDF) SetDeferFlowPageNum(v bool)
- func (l *LayoutPDF) SetPageNumRenderer(fn func(layout *LayoutPDF, page, pageCount int))
- func (l *LayoutPDF) SetRunningFooterTemplateFromElement(name string, footerElem pdfdom.PDFElementNode) error
- func (l *LayoutPDF) SetWarningFunc(fn func(format string, args ...any))
- func (l *LayoutPDF) StartFlow()
- func (l *LayoutPDF) TableDefFromElement(table *pdfdom.ElemTable, availableWidth float64) (*TableDef, error)
- func (l *LayoutPDF) TemplateByName(name string) (gofpdf.Template, error)
- func (l *LayoutPDF) TotalPages() int
- type PDFDocumentNode
- type PDFElementNode
- type PDFNode
- type PDFTextBox
- type PDFTextEngine
- func (e *PDFTextEngine) GlyphRegistry() *FontGlyphRegistry
- func (e *PDFTextEngine) Measure(node PDFNode) (PDFTextMetrics, error)
- func (e *PDFTextEngine) MeasureInBox(node PDFNode, box *PDFTextBox) (PDFTextMetrics, error)
- func (e *PDFTextEngine) Render(node PDFNode) (PDFTextMetrics, error)
- func (e *PDFTextEngine) RenderInBox(node PDFNode, box *PDFTextBox) (PDFTextMetrics, error)
- func (e *PDFTextEngine) SetDefaultStyle(style PDFTextStyle)
- func (e *PDFTextEngine) SetImageLoader(loader ImageLoader)
- func (e *PDFTextEngine) SetImageSearchDirs(paths []string)
- func (e *PDFTextEngine) SetValueFormatter(formatter pdfdom.ValueFormatter)
- type PDFTextMetrics
- type PDFTextNode
- type PDFTextStyle
- type PageLimitError
- type RowDef
- type TableDef
- type TableRenderer
- type TemplateFactory
- type TextAlign
- type Translator
Constants ¶
const ( LogoBaseRadius = 16.5 LogoTplExtent = 3.4 * LogoBaseRadius LogoTplCenter = LogoTplExtent / 2 )
const ( TextAlignLeft = pdfdom.TextAlignLeft TextAlignCenter = pdfdom.TextAlignCenter TextAlignRight = pdfdom.TextAlignRight TextFitClip = pdfdom.TextFitClip TextFitWrap = pdfdom.TextFitWrap )
Variables ¶
This section is empty.
Functions ¶
func CreateRingLogoTemplate ¶
func ExtractRunningFooterElement ¶
func ExtractRunningFooterElement(elements []pdfdom.PDFElementNode, name string) (matchedName string, elem pdfdom.PDFElementNode, remaining []pdfdom.PDFElementNode)
ExtractRunningFooterElement finds the first element with position="running(name)" and returns the matched name, the element, and a filtered slice without it. When name is empty, the first element with any position="running(...)" value is matched. Returns ("", nil, elements) when no match is found.
func RenderDocTemplateFlow ¶
func RenderDocTemplateFlow(l *LayoutPDF, elements []pdfdom.PDFElementNode) error
RenderDocTemplateFlow renders a document flow from pre-built PDFDOM elements. Elements with CSS position:running(name) are extracted, registered as running footer templates, and stamped on every page via BeginPage.
func RenderDocTemplateOverlay ¶
func RenderDocTemplateOverlay(l *LayoutPDF, elements []pdfdom.PDFElementNode) error
RenderDocTemplateOverlay renders page-local content without advancing the persistent normal-flow cursor.
func RenderLogoPDF ¶
func ShouldBreakPageAfter ¶
func ShouldBreakPageAfter(node pdfdom.PDFElementNode) bool
ShouldBreakPageAfter reports whether node carries a break-after:page attribute.
func ShouldBreakPageBefore ¶
func ShouldBreakPageBefore(node pdfdom.PDFElementNode) bool
ShouldBreakPageBefore reports whether node carries a break-before:page attribute.
Types ¶
type CellDef ¶
type CellDef struct {
Text string
SubText string
FontFace string
FontStyle string
FontSize float64
FontColor string
Background string
LineHeight float64
Value interface{}
Type string
Align string
PaddingTop float64
PaddingRight float64
PaddingBottom float64
PaddingLeft float64
Bold bool
Small bool
SubFontFace string
SubFontColor string
SubFontSize float64
NoWrap bool
Colspan int
}
CellDef defines a cell.
type CellFormatter ¶
type CellFormatter interface {
FormatCurrency(value float64) string
FormatFloat(value float64, decimals int) string
FormatDate(dateStr string, long bool) string
FormatWorkWeek(dateStr string) string
FormatDuration(hours float64) string
}
CellFormatter formats typed cell values into locale-aware strings. Implemented by *invoice.Formatter; defined here to avoid an import cycle.
type FontGlyphRegistry ¶
type FontGlyphRegistry struct {
// contains filtered or unexported fields
}
FontGlyphRegistry tracks used glyphs per font for later subsetting.
func NewFontGlyphRegistry ¶
func NewFontGlyphRegistry() *FontGlyphRegistry
func (*FontGlyphRegistry) Record ¶
func (g *FontGlyphRegistry) Record(fontFace, text string)
func (*FontGlyphRegistry) Snapshot ¶
func (g *FontGlyphRegistry) Snapshot() map[string][]rune
func (*FontGlyphRegistry) UsedGlyphs ¶
func (g *FontGlyphRegistry) UsedGlyphs(fontFace string) []rune
type FontRegistration ¶
type FontRegistration struct {
Family string
Style string
Sources []string
Data []byte
Name string
}
FontRegistration declares one font family/style with ordered candidate file paths. The first existing file path will be loaded.
type ImageLoader ¶
type ImageLoader func(name string) (ImageResource, error)
type ImageResource ¶
type LayoutOptions ¶
type LayoutOptions struct {
FontRegistrations []FontRegistration
ImageSearchDirs []string
ImageLoader ImageLoader
StrictRenderErrors bool
Context context.Context
MaxPages int
TemplateFactories map[string]TemplateFactory
MetadataTime time.Time
}
LayoutOptions controls optional renderer initialization behavior.
type LayoutPDF ¶
type LayoutPDF struct {
PDF *gofpdf.Fpdf
Formatter *format.Formatter
I18n *i18n.I18n
// contains filtered or unexported fields
}
LayoutPDF holds the shared PDF document and pre-built templates used by all standalone rendering subcommands. Build one with NewLayoutPDF; use the exported methods to compose pages.
func NewLayoutPDF ¶
func NewLayoutPDF(defaultPage, firstPage templateload.PageSettings, i18nInst *i18n.I18n, formatter *format.Formatter) (*LayoutPDF, error)
FontRegistration declares one font family/style with ordered candidate file paths. The first existing file path will be loaded. NewLayoutPDF creates a LayoutPDF from page settings and locale/format helpers.
func NewLayoutPDFWithOptions ¶
func NewLayoutPDFWithOptions(defaultPage, firstPage templateload.PageSettings, i18nInst *i18n.I18n, formatter *format.Formatter, options LayoutOptions) (*LayoutPDF, error)
NewLayoutPDFWithOptions creates a LayoutPDF and applies optional profile configuration such as custom font registrations.
func (*LayoutPDF) BeginPage ¶
BeginPage handles pagination (AddPage on page > 1) and stamps the running footer template on every page.
func (*LayoutPDF) CellDefFromTableCell ¶
func (l *LayoutPDF) CellDefFromTableCell(cellElem pdfdom.PDFElementNode, isHeader bool) CellDef
CellDefFromTableCell builds a CellDef from an HTML table cell element.
func (*LayoutPDF) CurrentFlowBottom ¶
CurrentFlowBottom returns the y coordinate of the bottom of the content area.
func (*LayoutPDF) CurrentFlowBox ¶
CurrentFlowBox returns the current page's content box origin and width.
func (*LayoutPDF) EnsureTotalPagesAtLeast ¶
EnsureTotalPagesAtLeast sets the total page count to n if n is larger than the current tracked value.
func (*LayoutPDF) NextFlowPage ¶
NextFlowPage advances to the next page in the flow.
func (*LayoutPDF) PageTemplateData ¶
PageTemplateData returns page/runtime metadata intended for template payloads. Values are resolved from the current layout state and optional explicit pageNumber/pageTotal overrides.
func (*LayoutPDF) RenderCreateTemplateElement ¶
func (l *LayoutPDF) RenderCreateTemplateElement(elem *pdfdom.ElemCreateTemplate) error
RenderCreateTemplateElement captures an element's children in a named template.
func (*LayoutPDF) RenderFinalFlowPageNums ¶
func (l *LayoutPDF) RenderFinalFlowPageNums()
RenderFinalFlowPageNums re-renders page numbers on all non-first pages after the total page count is known.
func (*LayoutPDF) RenderPageNum ¶
RenderPageNum draws the current/total page number in the top-right corner. It is a no-op on page 1.
func (*LayoutPDF) RenderUseTemplateElement ¶
func (l *LayoutPDF) RenderUseTemplateElement(elem *pdfdom.ElemUseTemplate, fallbackX, fallbackY float64) (renderedHeight float64, absolute bool, err error)
RenderUseTemplateElement renders a <use-template> element using the named template. fallbackX and fallbackY are the current document-flow coordinates; they are used when the element does not carry explicit x or y attributes. Returns the rendered height, whether an explicit position was given (absolute=true means the caller should NOT advance the flow cursor), and any error.
func (*LayoutPDF) ResolveFlowPlacement ¶
func (l *LayoutPDF) ResolveFlowPlacement(node pdfdom.PDFElementNode, flowX, flowY, flowW float64) (x, y, width float64, absolute bool)
ResolveFlowPlacement determines the final position and width of a flow element, applying absolute positioning when declared.
func (*LayoutPDF) ResolvePDFTextNode ¶
func (l *LayoutPDF) ResolvePDFTextNode(node *pdfdom.PDFTextNode) string
func (*LayoutPDF) SetDeferFlowPageNum ¶
SetDeferFlowPageNum controls whether page numbers are deferred until RenderFinalFlowPageNums.
func (*LayoutPDF) SetPageNumRenderer ¶
SetPageNumRenderer sets the callback used to render page numbers.
func (*LayoutPDF) SetRunningFooterTemplateFromElement ¶
func (l *LayoutPDF) SetRunningFooterTemplateFromElement(name string, footerElem pdfdom.PDFElementNode) error
func (*LayoutPDF) SetWarningFunc ¶
SetWarningFunc sets the warning sink used by non-fatal renderer warnings. Passing nil disables warning output.
func (*LayoutPDF) StartFlow ¶
func (l *LayoutPDF) StartFlow()
StartFlow initialises page tracking and persistent normal-flow state.
func (*LayoutPDF) TableDefFromElement ¶
func (*LayoutPDF) TemplateByName ¶
TemplateByName returns the pre-built gofpdf.Template for a named slot.
func (*LayoutPDF) TotalPages ¶
TotalPages returns the current tracked total page count.
type PDFDocumentNode ¶
type PDFDocumentNode = pdfdom.PDFDocumentNode
type PDFElementNode ¶
type PDFElementNode = pdfdom.PDFElementNode
type PDFTextBox ¶
type PDFTextBox = pdfdom.PDFTextBox
type PDFTextEngine ¶
type PDFTextEngine struct {
// contains filtered or unexported fields
}
PDFTextEngine hides low-level PDF calls and renders declarative PDFNode trees.
func NewPDFTextEngine ¶
func NewPDFTextEngine(pdf *gofpdf.Fpdf, i18n Translator) *PDFTextEngine
func (*PDFTextEngine) GlyphRegistry ¶
func (e *PDFTextEngine) GlyphRegistry() *FontGlyphRegistry
func (*PDFTextEngine) Measure ¶
func (e *PDFTextEngine) Measure(node PDFNode) (PDFTextMetrics, error)
func (*PDFTextEngine) MeasureInBox ¶
func (e *PDFTextEngine) MeasureInBox(node PDFNode, box *PDFTextBox) (PDFTextMetrics, error)
func (*PDFTextEngine) Render ¶
func (e *PDFTextEngine) Render(node PDFNode) (PDFTextMetrics, error)
func (*PDFTextEngine) RenderInBox ¶
func (e *PDFTextEngine) RenderInBox(node PDFNode, box *PDFTextBox) (PDFTextMetrics, error)
func (*PDFTextEngine) SetDefaultStyle ¶
func (e *PDFTextEngine) SetDefaultStyle(style PDFTextStyle)
func (*PDFTextEngine) SetImageLoader ¶
func (e *PDFTextEngine) SetImageLoader(loader ImageLoader)
func (*PDFTextEngine) SetImageSearchDirs ¶
func (e *PDFTextEngine) SetImageSearchDirs(paths []string)
func (*PDFTextEngine) SetValueFormatter ¶
func (e *PDFTextEngine) SetValueFormatter(formatter pdfdom.ValueFormatter)
type PDFTextMetrics ¶
PDFTextMetrics contains calculated dimensions and rendering metadata.
type PDFTextNode ¶
type PDFTextNode = pdfdom.PDFTextNode
type PDFTextStyle ¶
type PDFTextStyle = pdfdom.PDFTextStyle
type PageLimitError ¶
func (*PageLimitError) Error ¶
func (e *PageLimitError) Error() string
func (*PageLimitError) Is ¶
func (e *PageLimitError) Is(target error) bool
type RowDef ¶
type RowDef struct {
Cells []CellDef
Height float64
Header bool
Background string
Fill string
Border bool
Stroke *bool
}
RowDef defines a row.
type TableDef ¶
type TableDef struct {
Title string
Width float64
TableLayout string
Padding float64
RowHeightMin float64
MarginTop float64
MarginBottom float64
MarginTopSet bool
MarginBottomSet bool
Background string
BorderColor string
BorderStyle string
BorderWidth float64
Columns []ColumnDef
Rows []RowDef
}
TableDef defines a table structure.
type TableRenderer ¶
type TableRenderer struct {
// contains filtered or unexported fields
}
TableRenderer handles rendering tables in PDF documents.
func NewTableRenderer ¶
func NewTableRenderer(pdf *gofpdf.Fpdf, formatter CellFormatter) *TableRenderer
NewTableRenderer creates a new table renderer.
func (*TableRenderer) MeasureTableHeight ¶
func (tr *TableRenderer) MeasureTableHeight(table *TableDef) (float64, error)
MeasureTableHeight returns the height that RenderTable would consume (excluding the trailing 5pt cursor gap).
func (*TableRenderer) RenderTable ¶
func (tr *TableRenderer) RenderTable(table *TableDef) error
RenderTable renders a table at the current PDF cursor position.
type Translator ¶
type Translator = pdfdom.Translator
Source Files
¶
- create_template.go
- element_attributes.go
- flow_state.go
- font_glyph_registry.go
- geometry.go
- layout.go
- render_errors.go
- resources.go
- ring_logo.go
- running_footer.go
- table_cell.go
- table_conversions.go
- table_layout.go
- table_pagination.go
- table_renderer.go
- table_spans.go
- template_renderers.go
- text_continuation.go
- text_engine.go
- text_helpers.go
- text_plan_render.go