document

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePDFInProjectRootOutFolder

func CreatePDFInProjectRootOutFolder(pdf *gofpdf.Fpdf, fileName string) error

TODO: add functionality to generate example files from tests. ONLY FOR TEST

Types

type AlignmentType

type AlignmentType int

AlignmentType determines how the content is aligned inside a cell.

cell: #----------------------------------------------# | AlignTopLeft AlignTop AlignTopRight | | | | AlignLeft AlignCenter AlignRight | | | | AlignBottomLeft AlignBottom AlignBottomRight | #----------------------------------------------#

Possible values:

  • AlignCenter
  • AlignTop
  • AlignRight
  • AlignBottom
  • AlignLeft
  • AlignTopLeft
  • AlignTopRight
  • AlignBottomRight
  • AlignBottomLeft
const (
	AlignCenter AlignmentType = iota
	AlignTop
	AlignRight
	AlignBottom
	AlignLeft
	AlignTopLeft
	AlignTopRight
	AlignBottomRight
	AlignBottomLeft
)

type BorderType

type BorderType int

BorderType determines how a border will be rendered.

Possible values:

  • BorderNone
  • BorderOutside
  • BorderInside
  • BorderTop
  • BorderRight
  • BorderBottom
  • BorderLeft
  • BorderX
  • BorderY
  • BorderTopAndLeft
  • BorderTopAndRight
  • BorderBottomAndRight
  • BorderBottomAndLeft
  • BorderOpenTop
  • BorderOpenRight
  • BorderOpenBottom
  • BorderOpenLeft
const (
	BorderUnset BorderType = iota
	BorderNone
	BorderOutside
	BorderInside // e.g. table
	BorderTop
	BorderRight
	BorderBottom
	BorderLeft
	BorderX // BorderLeft + BorderRight
	BorderY // BorderTop + BorderBottom
	BorderTopAndLeft
	BorderTopAndRight
	BorderBottomAndRight
	BorderBottomAndLeft
	BorderOpenTop    // BorderRight + BorderBottom + BorderLeft
	BorderOpenRight  // BorderBottom + BorderLeft + BorderTop
	BorderOpenBottom // BorderLeft + BorderTop + BorderRight
	BorderOpenLeft   // BorderTop + BorderRight + BorderBottom
)

type BoxType

type BoxType int

BoxType determines if content has to fit inside the box or it will be continued on another box on the same or subsequent page.

BoxUnset (default) - BoxType is not set

BoxOpen - content will be continued when it does not fit the box entirely.

BoxClosed - content has to fit the box, otherwise this should lead to an error.

const (
	BoxUnset BoxType = iota
	BoxOpen
	BoxClosed
)

type CellType

type CellType int

CellType determines how a cell will be rendered.

const (
	CellSingle CellType = iota
	CellMulti
)

type ColumnType

type ColumnType int

CollumnType determines how a column width will be calculated.

const (
	ColCalc ColumnType = iota
	ColFixed
	ColDyn
)

type Doc

type Doc struct {
	*gofpdf.Fpdf
	// contains filtered or unexported fields
}

func NewA4

func NewA4() *Doc

NewA4 creates a new pdf in DIN A4 format with one page added.

Orientation: portrait

lang: en

unit: mm

size: A4

font: Arial

fontSize: 8

lineHeight: 1.2

document margins: left: 10, top: 10, right: 10

line width: 0.2

func NewA4WithDefaults

func NewA4WithDefaults(setDetaultsFunc *func(*gofpdf.Fpdf)) *Doc

NewA4 creates a new pdf in DIN A4 format with one page added.

Orientation: portrait

lang: en

unit: mm

size: A4

font: Arial

fontSize: 8

lineHeight: 1.2

document margins: left: 10, top: 10, right: 10

line width: 0.2

func (*Doc) AddImage

func (doc *Doc) AddImage(dto *Image) (*gofpdf.ImageInfoType, error)

func (*Doc) CFormat

func (d *Doc) CFormat(w, h float64, txtStr, borderStr string, ln int,
	alignStr string, fill bool, link int, linkStr string)

CFormat wraps CellFormat and transforms the given txtStr in a UTF-8 UnicodeTranslator to render special characters such as german Umlaute

func (*Doc) Ellipsis

func (d *Doc) Ellipsis() string

Ellipsis are three dots (...) representing that a string is longer than it is displayed

func (*Doc) GetFontLineHeight

func (d *Doc) GetFontLineHeight() float64

func (*Doc) GetLineHeight

func (d *Doc) GetLineHeight() float64

func (*Doc) GetPrintHeight

func (d *Doc) GetPrintHeight() float64

GetPrintHeight returns the current print height, which is the page height subtracted by the top and bottom margin.

func (*Doc) GetPrintWidth

func (d *Doc) GetPrintWidth() float64

GetPrintWidth returns the current print width, which is the page width subtracted by the left and right margin.

func (*Doc) GetRemainingPrintHeight

func (d *Doc) GetRemainingPrintHeight() float64

GetRemainingPrintHeight returns the remaining print height, which is the page height subtracted by the bottom margin and the current cursor-position, can be negative.

func (*Doc) MCell

func (d *Doc) MCell(w, h float64, txtStr, borderStr, alignStr string, fill bool)

CFormat wraps MultiCell and transforms the given txtStr in a UTF-8 UnicodeTranslator to render special characters such as german Umlaute

func (*Doc) SetLineHeight

func (d *Doc) SetLineHeight(lh float64)

SetLineHeight sets the line height. Values 0 and lower will be disgarded.

func (*Doc) VerticalLine

func (d *Doc) VerticalLine(x1, x2, thickness float64)

VerticalLine draws a vertical line on the current y position from x1 to x2 with a given thinkness.

func (*Doc) VerticalLinePrintWidth

func (d *Doc) VerticalLinePrintWidth()

VerticalLinePrintWidth draws a vertical line inside the current print width with a thickness of Fpdf.GetLineWidth().

type DocTable

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

DocTable

NOTE: All used indices follow the convention that indices i are for rows and indices j are for columns.

Render process: 1-3 are user actions

1. NewDocTable(doc *Doc, cells [][]string)

  • setting row and column count

  • setting default values

2. (optional) change table parameters

3. table.Generate()

  • validate columns

  • calculate columns

  • validate rows

  • calculate rows

  • render cells

Table parameters & defaults:

  • colTypes: ColDyn
  • colFixedWidths: 0.0
  • colGaps: 0.0
  • colWidths: calculated
  • rowTypes: RowCalc
  • rowFixedHeights: 0.0
  • rowGaps: 0.0
  • rowHeights: calculated
  • cells: constructor parameter
  • cellTypes: CellSingle
  • cellLineHeightFactors: 1.2
  • cellAligns: AlignLeft
  • cellPaddings: Padding{0,0,0,0}
  • cellBorder: true

func NewDocTable

func NewDocTable(doc *Doc, cells [][]string, args ...interface{}) (*DocTable, error)

NewDocTable creats a DocTable given a *Doc and cells. An error will be returned when given cell dimensions are not valid (e.g. one row is shorter than the others).

func (*DocTable) Generate

func (t *DocTable) Generate() error

func (*DocTable) SetAllCellAligns

func (t *DocTable) SetAllCellAligns(a AlignmentType)

func (*DocTable) SetAllCellBorders

func (t *DocTable) SetAllCellBorders(b bool)

func (*DocTable) SetAllCellLineHeightFactors

func (t *DocTable) SetAllCellLineHeightFactors(f float64)

func (*DocTable) SetAllCellPaddings

func (t *DocTable) SetAllCellPaddings(p Padding)

func (*DocTable) SetAllCellStyleFuncs

func (t *DocTable) SetAllCellStyleFuncs(f *func(gofpdf.Fpdf))

TODO: Add SetCellStyleFunc

func (*DocTable) SetAllCellTypes

func (t *DocTable) SetAllCellTypes(ct CellType)

func (*DocTable) SetAllColFixedWidths

func (t *DocTable) SetAllColFixedWidths(w float64)

func (*DocTable) SetAllColGaps

func (t *DocTable) SetAllColGaps(g float64)

func (*DocTable) SetAllColTypes

func (t *DocTable) SetAllColTypes(ct ColumnType)

func (*DocTable) SetAllRowFixedHeights

func (t *DocTable) SetAllRowFixedHeights(f float64)

func (*DocTable) SetAllRowGaps

func (t *DocTable) SetAllRowGaps(g float64)

func (*DocTable) SetAllRowTypes

func (t *DocTable) SetAllRowTypes(rt RowType)

func (*DocTable) SetCell

func (t *DocTable) SetCell(i, j int, str string) error

func (*DocTable) SetCellAlingsPerColumn

func (t *DocTable) SetCellAlingsPerColumn(a []AlignmentType) error

func (*DocTable) SetCellPaddings

func (t *DocTable) SetCellPaddings(p [][]Padding) error

func (*DocTable) SetCellPaddingsPerColumn

func (t *DocTable) SetCellPaddingsPerColumn(p []Padding) error

func (*DocTable) SetCellStyleFuncsPerAlternateRows

func (t *DocTable) SetCellStyleFuncsPerAlternateRows(f1, f2 *func(gofpdf.Fpdf))

func (*DocTable) SetCellStyleFuncsPerColumn

func (t *DocTable) SetCellStyleFuncsPerColumn(fs []*func(gofpdf.Fpdf)) error

func (*DocTable) SetCellStyleFuncsPerRow

func (t *DocTable) SetCellStyleFuncsPerRow(fs []*func(gofpdf.Fpdf)) error

func (*DocTable) SetCellStyleFuncsRow

func (t *DocTable) SetCellStyleFuncsRow(i int, f *func(gofpdf.Fpdf)) error

func (*DocTable) SetCellType

func (t *DocTable) SetCellType(i, j int, ct CellType) error

func (*DocTable) SetCellTypesPerColumn

func (t *DocTable) SetCellTypesPerColumn(ct []CellType) error

func (*DocTable) SetColFixedWidths

func (t *DocTable) SetColFixedWidths(cFixedWidth []float64) error

func (*DocTable) SetColGaps

func (t *DocTable) SetColGaps(g []float64) error

func (*DocTable) SetColTypes

func (t *DocTable) SetColTypes(colTypes []ColumnType) error

func (*DocTable) SetDefaults

func (t *DocTable) SetDefaults()

func (*DocTable) SetHeadType

func (t *DocTable) SetHeadType(ht HeadType)

TABLE PARAMETER SETTERS

func (*DocTable) SetRowFixedHeights

func (t *DocTable) SetRowFixedHeights(f []float64) error

func (*DocTable) SetRowGaps

func (t *DocTable) SetRowGaps(g []float64) error

func (*DocTable) SetRowTypes

func (t *DocTable) SetRowTypes(rt []RowType) error

type FillType

type FillType int
const (
	FillUnset FillType = iota
	FillNone
	Fill
	FillGradientLinear
	FillGradientRadial
)

type FlowType

type FlowType int

FlowType determines where the cursor will positioned after generate.

FlowInline - cursor on the same height after the element.

FlowBlock - cursor under and at the beginning of the element.

FlowNewline - cursor under the element and at the left margin

const (
	FlowUnset FlowType = iota
	FlowInline
	FlowBlock
	FlowNewline
)

type HAlignmentType

type HAlignmentType int

HAlignmentType determines how content is aligned horizontally in a cell:

#-----------------------------------------# | | | HAlignLeft HAlignCenter HAlignRight | | | #-----------------------------------------#

const (
	HAlignUnset HAlignmentType = iota
	HAlignLeft
	HAlignCenter
	HAlignRight
)

type HeadType

type HeadType int

HeadType

const (
	HeadUnset HeadType = iota
	HeadNone
	HeadFirstRow
)

type Image

type Image struct {
	ImageUrl *string `json:"imageUrl" validate:"required"`
}

type LayoutType

type LayoutType string
const (
	LayoutTypeDIN5008A LayoutType = "DIN_5008A"
	LayoutTypeDIN5008B LayoutType = "DIN_5008B"
)

type OrientationType

type OrientationType int
const (
	OrientationUnset OrientationType = iota
	OrientationPortrait
	OrientationLandscape
)

type Padding

type Padding [4]float64

Padding is the padding inside of a cell. The indices follow the convention Top(0), Right(1), Bottom(2), Left(3).

#-- border -------------------------# | paddingTop | | #------# | | paddingLeft | cell | paddingRight | | #------# | | paddingBottom | #-----------------------------------#

type PositionType

type PositionType int

PositionType determines how an element gets positioned.

PositionAbsolute - place an element at the coordinates x, y on the current page.

PositionsRelative - place an element at the current cursor position.

const (
	PositionUnset PositionType = iota
	PositionAbsolute
	PositionRelative
)

type RowType

type RowType int

RowType determines how a row height will be calculated.

const (
	RowCalc RowType = iota
	RowFixed
)

type UnitType

type UnitType int
const (
	UnitUnset UnitType = iota
	UnitMillimeter
	UnitPoint
	UnitCentimeter
	UnitInch
)

type VAlignmentType

type VAlignmentType int

VAlignmentType determines how content is aligned vertically in a cell:

#------------------# | VAlignTop | | | | VAlignMiddle | | | | VAlignBottom | #------------------#

const (
	VAlignUnset VAlignmentType = iota
	VAlignTop
	VAlignMiddle
	VAlignBottom
)

Jump to

Keyboard shortcuts

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