reportbro

package module
v0.0.0-...-266fd98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2023 License: AGPL-3.0 Imports: 30 Imported by: 2

README

reportbro-lib-go

ReportBro Lib Go is the un-official library to generate PDF and XLSX reports. Report templates can be created with ReportBro Designer <https://github.com/jobsta/reportbro-designer>, a Javascript Plugin which can be integrated in your web application.

See the ReportBro project website on https://www.reportbro.com for full documentation and demos.

Table of contents

1. Overview

  • Generate pdf and xlsx reports
  • Supports (repeating) header and footer
  • Allows predefined and own page formats
  • Use text, line, images, barcodes and tables, page breaks
  • Text and element styling
  • Evaluate expressions, define conditional styles, format parameters

2. Quick Start

Install and import into your project.

go get github.com/GeorgeD19/reportbro-lib-go
import (
    "github.com/GeorgeD19/reportbro-lib-go"
)

3. Prerequisites

4. Install

Install go dependencies

go mod tidy

Install node packages for app example

cd app && npm install

5. Running

Start go server

cd app && go run server.go

Then open index.html in your browser.

6. Contributing

Read our Contribution Guidelines for information on how you can help out ReportBro Lib Go.

7. Reporting Issues

If you think you've found a bug, or something isn't behaving the way you think it should, please raise an issue on Github.

5. License

  • Commercial license

If you want to use ReportBro to develop commercial applications and projects, the Commercial license is the appropriate license. With this license, your source code is kept proprietary. Purchase a ReportBro Commercial license at https://www.reportbro.com/buy.

  • Open-source license

If you are creating an open-source application under a license compatible with the GNU AGPL license v3 <https://www.gnu.org/licenses/agpl-3.0.html>_, you may use ReportBro under the terms of the AGPLv3.

Read more about ReportBro's license options at https://www.reportbro.com/license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DataTypes = [...]string{
	"none",
	"int",
	"string",
	"float",
	"datetime",
	"tabletextelement",
}
View Source
var EVAL_DEFAULT_NAMES = map[string]interface{}{
	"True":  true,
	"False": false,
	"None":  nil,
}
View Source
var ParameterTypes = [...]string{
	"none",
	"string",
	"number",
	"boolean",
	"date",
	"array",
	"simple_array",
	"map",
	"sum",
	"average",
	"image",
}

Functions

func BoolPointer

func BoolPointer(i bool) *bool

func Get

func Get(data string, key string) string

func GetArrayChildren

func GetArrayChildren(data string, key string) []string

func GetBoolValue

func GetBoolValue(data map[string]interface{}, key string) bool

func GetFloatValue

func GetFloatValue(data map[string]interface{}, key string) float64

func GetIntValue

func GetIntValue(data map[string]interface{}, key string) int

GetIntValue retrieves int value if exists, if not returns 0

func GetObjectChildren

func GetObjectChildren(data string, key string) []string

func GetStringValue

func GetStringValue(data map[string]interface{}, key string) string

func GetValue

func GetValue(data map[string]interface{}, key string) interface{}

func IsBlack

func IsBlack(self *Color) bool

IsBlack returns true or false on whether or not the color is black and not transparent

func Merge

func Merge(primary map[string]interface{}, secondary map[string]interface{}) map[string]interface{}

func NewReport

func NewReport(reportDefinition map[string]interface{}, data map[string]interface{}, isTestData bool, additionalFonts string, imageData map[string][]byte) report

func NewReportBroError

func NewReportBroError(err Error) reportBroError

func NewTextStyle

func NewTextStyle(data map[string]interface{}, keyPrefix string) textStyle

func ReportBandPointer

func ReportBandPointer(i reportBand) *reportBand

func Round

func Round(x float64) float64

func StringPointer

func StringPointer(i string) *string

func Substring

func Substring(str, start, end string) ([]byte, error)

Types

type BandDisplay

type BandDisplay int
const (
	BandDisplayNever          BandDisplay = 1
	BandDisplayAlways         BandDisplay = 2
	BandDisplayNotOnFirstPage BandDisplay = 3
)

func GetBandDisplay

func GetBandDisplay(bandDisplay string) BandDisplay

func (BandDisplay) String

func (bandDisplay BandDisplay) String() string

type BandType

type BandType int
const (
	BandTypeHeader  BandType = 1
	BandTypeContent BandType = 2
	BandTypeFooter  BandType = 3
)

func GetBandType

func GetBandType(bandType string) BandType

func (BandType) String

func (bandType BandType) String() string

type BarCodeElement

type BarCodeElement struct {
	DocElement
	Content                string
	Format                 string
	DisplayValue           bool
	RemoveEmptyElement     bool
	SpreadsheetHide        bool
	SpreadsheetColumn      int
	SpreadsheetColspan     int
	SpreadsheetAddEmptyRow bool
	ImageKey               *string
	ImageHeight            float64
}

func NewBarCodeElement

func NewBarCodeElement(report *report, data map[string]interface{}) *BarCodeElement

type Border

type Border int
const (
	BorderGrid     Border = 1
	BorderFrameRow Border = 2
	BorderFrame    Border = 3
	BorderRow      Border = 4
	BorderNone     Border = 5
)

func GetBorder

func GetBorder(border string) Border

func (Border) String

func (border Border) String() string

type BorderStyle

type BorderStyle struct {
	BorderColor  Color
	BorderWidth  float64
	BorderAll    bool
	BorderLeft   bool
	BorderTop    bool
	BorderRight  bool
	BorderBottom bool
}

func NewBorderStyle

func NewBorderStyle(data map[string]interface{}, keyPrefix string) BorderStyle

type Color

type Color struct {
	ColorCode   string `json:"color_code"`
	R           int    `json:"r"`
	G           int    `json:"g"`
	B           int    `json:"b"`
	Transparent bool   `json:"transparent"`
}

Color

func ColorPointer

func ColorPointer(i Color) *Color

func NewColor

func NewColor(color string) Color

NewColor creates a new Color instance with defaults

type Container

type Container struct {
	ID                    string
	Report                *report
	DocElements           []DocElementBaseProvider
	Width                 float64
	Height                float64
	AllowPageBreak        bool
	ContainerOffsetY      float64
	SortedElements        []DocElementBaseProvider
	RenderElements        []DocElementBaseProvider
	RenderElementsCreated bool
	ExplicitPageBreak     bool
	PageY                 float64
	FirstElementOffsetY   float64
	UsedBandHeight        float64
	ManualPageBreak       bool
}

func NewContainer

func NewContainer(containerID string, containers *containers, report *report) Container

func (*Container) ClearRenderedElements

func (self *Container) ClearRenderedElements()

func (*Container) GetRenderElementsBottom

func (self *Container) GetRenderElementsBottom() float64

func (*Container) RenderSpreadsheet

func (self *Container) RenderSpreadsheet(row int, col int, ctx Context, renderer Renderer) (int, int)

type Context

type Context struct {
	Data                  map[string]interface{}
	DataStr               string // For debugging
	Report                *report
	PatternLocale         string
	PatternCurrencySymbol string
	RootData              map[string]interface{}
	// contains filtered or unexported fields
}

func NewContext

func NewContext(report report, parameters map[string]interface{}, data map[string]interface{}) Context

type DataType

type DataType int
const (
	DataTypeNone             DataType = 0
	DataTypeInt              DataType = 1
	DataTypeString           DataType = 2
	DataTypeFloat            DataType = 3
	DataTypeDatetime         DataType = 4
	DataTypeTableTextElement DataType = 5
)

func (DataType) String

func (DataType DataType) String() string

type DocElement

type DocElement struct {
	DocElementBase
}

func NewDocElement

func NewDocElement(report *report, data map[string]interface{}) *DocElement

type DocElementBase

type DocElementBase struct {
	Type                   string
	Report                 *report
	ID                     int
	Y                      float64
	RenderY                float64
	RenderBottom           float64
	Bottom                 float64
	Height                 float64
	PrintIf                string
	RemoveEmptyElement     bool
	SpreadsheetHide        bool
	SpreadsheetColumn      *string
	SpreadsheetAddEmptyRow bool
	FirstRenderElement     bool
	RenderingComplete      bool
	Predecessors           []DocElementBaseProvider
	Successors             []DocElementBaseProvider
	SortOrder              float64
	X                      float64
	Width                  float64
	RenderingBottom        bool
	Border                 Border
	BorderStyle            BorderStyle
	BackgroundColor        Color
	TotalHeight            float64
	UsedStyle              *textStyle
	Complete               bool
	TableElement           bool
	BorderColor            Color
	ZIndex                 int
}

func NewDocElementBase

func NewDocElementBase(report *report, data map[string]interface{}) *DocElementBase

func (*DocElementBase) GetOffsetY

func (self *DocElementBase) GetOffsetY() float64

type DocElementBaseProvider

type DocElementBaseProvider interface {
	// contains filtered or unexported methods
}

type DocElementType

type DocElementType int
const (
	DocElementTypeText        DocElementType = 1
	DocElementTypeImage       DocElementType = 2
	DocElementTypeLine        DocElementType = 3
	DocElementTypePageBreak   DocElementType = 4
	DocElementTypeTableBand   DocElementType = 5
	DocElementTypeTable       DocElementType = 6
	DocElementTypeTableText   DocElementType = 7
	DocElementTypeBarCode     DocElementType = 8
	DocElementTypeFrame       DocElementType = 9
	DocElementTypeSection     DocElementType = 10
	DocElementTypeSectionBand DocElementType = 11
)

func GetDocElementType

func GetDocElementType(docElementType string) DocElementType

func (DocElementType) String

func (docElementType DocElementType) String() string

type DocumentXLSXRenderer

type DocumentXLSXRenderer struct {
	// contains filtered or unexported fields
}

func (*DocumentXLSXRenderer) GenerateXlsx

func (self *DocumentXLSXRenderer) GenerateXlsx(filename string)

type Error

type Error struct {
	Message  string
	ObjectID int
	Field    string
	Info     interface{}
	// contains filtered or unexported fields
}

type FPDFRB

type FPDFRB struct {
	Fpdf            *gofpdf.Fpdf
	CMargin         int
	AdditionalFonts string
	X               float64
	Y               float64
	LoadedImages    map[string]string
	AvailableFonts  map[string]string
	Tr              func(string) string
}

type Frame

type Frame struct {
	Container
	X               float64
	Width           float64
	Height          float64
	BorderStyle     BorderStyle
	BackgroundColor Color
}

func NewFrame

func NewFrame(width float64, height float64, containerID string, containers *containers, report *report) *Frame

type FrameBlockElement

type FrameBlockElement struct {
	DocElementBase
	RemoveEmptyElement float64
	Elements           []DocElementBaseProvider
	RenderElementType  RenderElementType
	Complete           bool
}

func NewFrameBlockElement

func NewFrameBlockElement(report *report, frame DocElementBaseProvider, renderY float64) *FrameBlockElement

type FrameElement

type FrameElement struct {
	DocElement
	ShrinkToContentHeight     bool
	SpreadsheetColumn         int
	NextPageRenderingComplete bool
	PrevPageContentHeight     float64
	RenderElementType         RenderElementType
	Container                 *Frame
}

func NewFrameElement

func NewFrameElement(report *report, data map[string]interface{}, containers *containers) *FrameElement

type HorizontalAlignment

type HorizontalAlignment int
const (
	HorizontalAlignmentLeft    HorizontalAlignment = 1
	HorizontalAlignmentCenter  HorizontalAlignment = 2
	HorizontalAlignmentRight   HorizontalAlignment = 3
	HorizontalAlignmentJustify HorizontalAlignment = 4
)

func GetHorizontalAlignment

func GetHorizontalAlignment(horizontalAlignment string) HorizontalAlignment

func (HorizontalAlignment) String

func (horizontalAlignment HorizontalAlignment) String() string

type ImageElement

type ImageElement struct {
	DocElement
	Eval                   bool
	Source                 string
	Content                string
	IsContent              bool
	Image                  string
	ImageFile              string
	ImageFilename          string
	HorizontalAlignment    HorizontalAlignment
	VerticalAlignment      VerticalAlignment
	BackgroundColor        Color
	RemoveEmptyElement     bool
	Link                   string
	SpreadsheetHide        bool
	SpreadsheetColumn      int
	SpreadsheetAddEmptyRow bool
	ImageKey               string
	ImageType              string
	Image64                string
	ImageFP                []byte
	ImageHeight            float64
	UsedStyle              textStyle
	SpaceTop               float64
	SpaceBottom            float64
}

func NewImageElement

func NewImageElement(report *report, data map[string]interface{}) *ImageElement

type LineElement

type LineElement struct {
	DocElement
	Color Color
}

func NewLineElement

func NewLineElement(report *report, data map[string]interface{}) *LineElement

type Orientation

type Orientation int
const (
	OrientationPortrait  Orientation = 1
	OrientationLandscape Orientation = 2
)

func (Orientation) String

func (orientation Orientation) String() string

type PageBreakElement

type PageBreakElement struct {
	DocElementBase
}

func NewPageBreakElement

func NewPageBreakElement(report *report, data map[string]interface{}) *PageBreakElement

type PageFormat

type PageFormat int
const (
	PageFormatA4          PageFormat = 1
	PageFormatA5          PageFormat = 2
	PageFormatLetter      PageFormat = 3
	PageFormatUserDefined PageFormat = 4
)

func (PageFormat) String

func (pageFormat PageFormat) String() string

type Parameter

type Parameter struct {
	ID                 int
	Name               string
	Type               ParameterType
	ArrayItemType      ParameterType
	Eval               bool
	Nullable           bool
	Expression         string
	Pattern            string
	PatternHasCurrency bool
	IsInternal         bool
	Children           []interface{}
	Fields             map[string]interface{}
	// contains filtered or unexported fields
}

func NewParameter

func NewParameter(report *report, data map[string]interface{}) Parameter

type ParameterType

type ParameterType int
const (
	ParameterTypeNone        ParameterType = 0
	ParameterTypeString      ParameterType = 1
	ParameterTypeNumber      ParameterType = 2
	ParameterTypeBoolean     ParameterType = 3
	ParameterTypeDate        ParameterType = 4
	ParameterTypeArray       ParameterType = 5
	ParameterTypeSimpleArray ParameterType = 6
	ParameterTypeMap         ParameterType = 7
	ParameterTypeSum         ParameterType = 8
	ParameterTypeAverage     ParameterType = 9
	ParameterTypeImage       ParameterType = 10
)

func (ParameterType) String

func (ParameterType ParameterType) String() string

type RenderElementType

type RenderElementType int
const (
	RenderElementTypeNone     RenderElementType = 0
	RenderElementTypeComplete RenderElementType = 1
	RenderElementTypeBetween  RenderElementType = 2
	RenderElementTypeFirst    RenderElementType = 3
	RenderElementTypeLast     RenderElementType = 4
)

func GetRenderElementType

func GetRenderElementType(renderElementType string) RenderElementType

func (RenderElementType) String

func (renderElementType RenderElementType) String() string

type Renderer

type Renderer interface {
	// contains filtered or unexported methods
}

type SectionBand

type SectionBand struct {
	Height   float64
	Elements []DocElementBaseProvider
}

type SectionBandElement

type SectionBandElement struct {
	ID                    string
	Width                 float64
	Height                float64
	BandType              BandType
	RepeatHeader          bool
	AlwaysPrintOnSamePage bool
	ShrinkToContentHeight bool
	Container             Container
	RenderingComplete     bool
	PrepareContainer      bool
	RenderedBandHeight    float64
}

func NewSectionBandElement

func NewSectionBandElement(report *report, data map[string]interface{}, bandType BandType, container *containers) *SectionBandElement

type SectionBlockElement

type SectionBlockElement struct {
	DocElementBase
	Complete bool
	Bands    []SectionBand
}

func NewSectionBlockElement

func NewSectionBlockElement(report *report, renderY float64) *SectionBlockElement

type SectionElement

type SectionElement struct {
	DocElement
	DataSource          string
	Header              *SectionBandElement
	Content             *SectionBandElement
	Footer              *SectionBandElement
	PrintHeader         bool
	DataSourceparameter *Parameter
	RowParameters       map[string]interface{}
	RowCount            int
	RowIndex            int
	Rows                map[int]interface{}
}

func NewSectionElement

func NewSectionElement(report *report, data map[string]interface{}, containers *containers) *SectionElement

type Style

type Style interface {
	// contains filtered or unexported methods
}

type TableBandElement

type TableBandElement struct {
	ID                       int
	Height                   float64
	BandType                 BandType
	RepeatHeader             bool
	BackgroundColor          Color
	AlternateBackgroundColor *Color
	ColumnData               []interface{}
	GroupExpression          string
	PrintIf                  string
	BeforeGroup              bool
}

func NewTableBandElement

func NewTableBandElement(data map[string]interface{}, bandType BandType, beforeGroup bool) *TableBandElement

type TableBlockElement

type TableBlockElement struct {
	DocElementBase
	Table    DocElementBaseProvider
	Rows     []*TableRow
	Complete bool
}

func NewTableBlockElement

func NewTableBlockElement(report *report, x float64, width float64, renderY float64, table DocElementBaseProvider) *TableBlockElement

type TableElement

type TableElement struct {
	DocElement
	DataSource string
	Columns    []int

	PrintHeader            bool
	Footer                 *TableBandElement
	PrintFooter            bool
	ContentRows            []*TableBandElement
	BorderWidth            float64
	RemoveEmptyElement     bool
	SpreadsheetAddEmptyRow bool
	DataSourceparameter    *Parameter
	RowParameters          map[string]interface{}
	Rows                   []interface{}
	PreparedRows           []*TableRow
	RowCount               int
	RowIndex               int
	PrevContentRows        []*TableRow
	// contains filtered or unexported fields
}

func NewTableElement

func NewTableElement(report *report, data map[string]interface{}) *TableElement

type TableImageElement

type TableImageElement struct {
	ImageElement
}

func NewTableImageElement

func NewTableImageElement(report *report, data map[string]interface{}) *TableImageElement

type TableRow

type TableRow struct {
	ColumnData               []DocElementBaseProvider
	Height                   float64
	AlwaysPrintOnSamePage    bool
	TableBand                *TableBandElement
	RenderElements           []DocElementBaseProvider
	BackgroundColor          Color
	AlternateBackgroundColor *Color
	GroupExpression          string
	PrintIfResult            bool
	PrevRow                  *TableRow
	NextRow                  *TableRow
}

func NewTableRow

func NewTableRow(report *report, tableBand *TableBandElement, columns []int, ctx Context, prevRow *TableRow) *TableRow

type TableTextElement

type TableTextElement struct {
	TextElement
}

func NewTableTextElement

func NewTableTextElement(report *report, data map[string]interface{}) *TableTextElement

type TextBlockElement

type TextBlockElement struct {
	DocElementBase
	TextOffsetY       float64
	Lines             []TextLine
	LineHeight        float64
	RenderElementType RenderElementType
	Style             Style
}

func NewTextBlockElement

func NewTextBlockElement(report *report, x float64, y float64, renderY float64, width float64, height float64, textOffsetY float64, lines []TextLine, lineHeight float64, renderElementType RenderElementType, style Style) *TextBlockElement

type TextElement

type TextElement struct {
	DocElement
	Content                          string
	Eval                             bool
	Style                            textStyle
	Pattern                          string
	Link                             string
	CsCondition                      string
	ConditionalStyle                 *textStyle
	TextHeight                       float64
	LineIndex                        int
	LineHeight                       float64
	LinesCount                       int
	TextLines                        []TextLine
	SpaceTop                         float64
	SpaceBottom                      float64
	SpreadsheetCellFormat            *int
	SpreadsheetCellFormatinitialized bool
	SpreadsheetColspan               int
	AlwaysPrintOnSamePage            bool
}

func NewTextElement

func NewTextElement(report *report, data map[string]interface{}) *TextElement

type TextLine

type TextLine struct {
	Text  string
	Width float64
	Style Style
	Link  string
}

func NewTextLine

func NewTextLine(text string, width float64, style Style, link string) TextLine

type Unit

type Unit int
const (
	UnitPt   Unit = 1
	UnitMm   Unit = 2
	UnitInch Unit = 3
)

func GetUnit

func GetUnit(unit string) Unit

func (Unit) String

func (unit Unit) String() string

type VerticalAlignment

type VerticalAlignment int
const (
	VerticalAlignmentTop    VerticalAlignment = 1
	VerticalAlignmentMiddle VerticalAlignment = 2
	VerticalAlignmentBottom VerticalAlignment = 3
)

func GetVerticalAlignment

func GetVerticalAlignment(verticalAlignment string) VerticalAlignment

func (VerticalAlignment) String

func (verticalAlignment VerticalAlignment) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL