bpdf

package module
v0.0.0-...-40a6ac2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

bpdf

GoDoc Go Report Card

Fast and simple PDF creation. Inspired by Bootstrap and uses Gofpdf.

You can create PDFs as if you were creating a website with Bootstrap. A row can have many columns, and a column can have many components. In addition, pages will be added when the content may go beyond the useful area. You can define a header that will always be added when a new page appears. In this case, the header can contain many rows, lines, or tables.

Installation:
go get github.com/pchchv/bpdf

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfgs ...*entity.Config) core.BPDF

New is responsible for create a new instance of core.BPDF. It's optional to provide an *entity.Config with customizations those customization are created by using the config.Builder.

Example

ExampleNew demonstrates how to create a bpdf instance.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

func main() {
	// optional
	b := config.NewBuilder()
	cfg := b.Build()

	m := bpdf.New(cfg) // cfg is an optional

	// Do things and generate
	_, _ = m.Generate()
}
Output:

func NewMetricsDecorator

func NewMetricsDecorator(inner core.BPDF) core.BPDF

NewMetricsDecorator is responsible to create the metrics decorator for the bpdf instance.

Example

ExampleNewMetricsDecorator demonstrates how to create a bpdf metrics decorator instance.

package main

import (
	"github.com/pchchv/bpdf"
	"github.com/pchchv/bpdf/config"
)

func main() {
	// optional
	b := config.NewBuilder()
	cfg := b.Build()

	mrt := bpdf.New(cfg)               // cfg is an optional
	m := bpdf.NewMetricsDecorator(mrt) // decorator of bpdf

	// Do things and generate
	_, _ = m.Generate()
}
Output:

Types

type Bpdf

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

func (*Bpdf) AddAutoRow

func (m *Bpdf) AddAutoRow(cols ...core.Col) core.Row

AddAutoRow is responsible for adding a line with automatic height to the current document. The row height will be calculated based on its content.

func (*Bpdf) AddPages

func (m *Bpdf) AddPages(pages ...core.Page)

AddPages is responsible for add pages directly in the document. By adding a page directly, the current cursor will reset and the new page will appear as the next. If the page provided have more rows than the maximum useful area of a page, bpdf will split that page in more than one.

func (*Bpdf) AddRow

func (m *Bpdf) AddRow(rowHeight float64, cols ...core.Col) core.Row

AddRow is responsible for add one row in the current document. By adding a row, if the row will extrapolate the useful area of a page, bpdf will automatically add a new page. bpdf use the information of PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful area of a page.

func (*Bpdf) AddRows

func (m *Bpdf) AddRows(rows ...core.Row)

AddRows is responsible for add rows in the current document. By adding a row, if the row will extrapolate the useful area of a page, bpdf will automatically add a new page. bpdf use the information of PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful area of a page.

func (*Bpdf) FitlnCurrentPage

func (m *Bpdf) FitlnCurrentPage(heightNewLine float64) bool

FitlnCurrentPage is responsible to validating whether a line fits on the current page.

func (*Bpdf) Generate

func (m *Bpdf) Generate() (core.Document, error)

Generate computes the component tree created by all other bpdf methods and for generating the PDF document.

func (*Bpdf) GetCurrentConfig

func (m *Bpdf) GetCurrentConfig() *entity.Config

GetCurrentConfig is responsible for returning the current settings from the file.

func (*Bpdf) GetStructure

func (m *Bpdf) GetStructure() *node.Node[core.Structure]

GetStructure is responsible for return the component tree, this is useful on unit tests cases.

func (*Bpdf) RegisterFooter

func (m *Bpdf) RegisterFooter(rows ...core.Row) error

RegisterFooter is responsible to define a set of rows as a footer of the document. The footer will appear in every new page of the document. The footer cannot occupy an area greater than the useful area of the page, it this case the method will return an error.

func (*Bpdf) RegisterHeader

func (m *Bpdf) RegisterHeader(rows ...core.Row) error

RegisterHeader is responsible to define a set of rows as a header of the document. The header will appear in every new page of the document. The header cannot occupy an area greater than the useful area of the page, it this case the method will return an error.

type MetricsDecorator

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

func (*MetricsDecorator) AddAutoRow

func (m *MetricsDecorator) AddAutoRow(cols ...core.Col) core.Row

AddAutoRow decorates the AddRow method of bpdf instance.

func (*MetricsDecorator) AddPages

func (m *MetricsDecorator) AddPages(pages ...core.Page)

AddPages decorates the AddPages method of bpdf instance.

func (*MetricsDecorator) AddRow

func (m *MetricsDecorator) AddRow(rowHeight float64, cols ...core.Col) core.Row

AddRow decorates the AddRow method of bpdf instance.

func (*MetricsDecorator) AddRows

func (m *MetricsDecorator) AddRows(rows ...core.Row)

AddRows decorates the AddRows method of bpdf instance.

func (*MetricsDecorator) FitlnCurrentPage

func (m *MetricsDecorator) FitlnCurrentPage(heightNewLine float64) bool

FitlnCurrentPage decoratess the FitlnCurrentPage method of bpdf instance.

func (*MetricsDecorator) Generate

func (m *MetricsDecorator) Generate() (doc core.Document, err error)

Generate decorates the Generate method of bpdf instance.

func (*MetricsDecorator) GetCurrentConfig

func (m *MetricsDecorator) GetCurrentConfig() *entity.Config

GetCurrentConfig decorates the GetCurrentConfig method of bpdf instance.

func (*MetricsDecorator) GetStructure

func (m *MetricsDecorator) GetStructure() *node.Node[core.Structure]

GetStructure decorates the GetStructure method of bpdf instance.

func (*MetricsDecorator) RegisterFooter

func (m *MetricsDecorator) RegisterFooter(rows ...core.Row) (err error)

RegisterFooter decorates the RegisterFooter method of bpdf instance.

func (*MetricsDecorator) RegisterHeader

func (m *MetricsDecorator) RegisterHeader(rows ...core.Row) (err error)

RegisterHeader decorates the RegisterHeader method of bpdf instance.

Directories

Path Synopsis
cmd
Package components contains the public components of bpdf.
Package components contains the public components of bpdf.
code
Package code implements creation of Barcode, MatrixCode and QrCode.
Package code implements creation of Barcode, MatrixCode and QrCode.
col
Package col implements creation of columns.
Package col implements creation of columns.
image
Package image implements creation of images from file and bytes.
Package image implements creation of images from file and bytes.
list
Package list implements creation of lists (old tablelist).
Package list implements creation of lists (old tablelist).
page
Page package implements creation of pages.
Page package implements creation of pages.
row
Package row implements creation of rows.
Package row implements creation of rows.
signature
Package signature implements creation of signatures.
Package signature implements creation of signatures.
text
Package text implements creation of texts.
Package text implements creation of texts.
Package config implements custom configuration builder.
Package config implements custom configuration builder.
The consts package contains the public constants of bpdf.
The consts package contains the public constants of bpdf.
align
The align package contains all align types.
The align package contains all align types.
border
The border package contains all border types.
The border package contains all border types.
breakline
The breakline package contains all break line strategies.
The breakline package contains all break line strategies.
extension
The extension package contains all image extensions.
The extension package contains all image extensions.
fontfamily
The fontfamily package contains all default font families.
The fontfamily package contains all default font families.
fontstyle
The fontstyle package contains all default font styles.
The fontstyle package contains all default font styles.
linestyle
The linestyle package contains all line styles.
The linestyle package contains all line styles.
orientation
Package orientation contains all orientations.
Package orientation contains all orientations.
pagesize
Package pagesize contains all default page sizes.
Package pagesize contains all default page sizes.
protection
The protection package contains all protection types.
The protection package contains all protection types.
provider
The provider package contains all document generation providers.
The provider package contains all document generation providers.
The core package contains all core interfaces and basic implementations.
The core package contains all core interfaces and basic implementations.
internal
Package merge implements PDF merge.
Package merge implements PDF merge.
Package metrics contains metrics models, constants and formatting.
Package metrics contains metrics models, constants and formatting.
The properties package contain the public properties of bpdf.
The properties package contain the public properties of bpdf.
Package test implements unit test feature.
Package test implements unit test feature.

Jump to

Keyboard shortcuts

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