maroto

package module
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: MIT Imports: 17 Imported by: 7

README

Maroto V2

GoDoc Go Report Card Mentioned in Awesome Go
CI Lint Codecov Visits Badge

A Maroto way to create PDFs. Maroto is inspired in Bootstrap and uses Gofpdf. Fast and simple.

sirmaroto

Maroto definition: Brazilian expression, means an astute/clever/intelligent person. Art by @marinabankr

You can write your PDFs like you are creating a site using Bootstrap. A Row may have many Cols, and a Col may have many components. Besides that, pages will be added when content may extrapolate the useful area. You can define a header which will be added always when a new page appear, in this case, a header may have many rows, lines or tablelist.

Maroto v2.0.4 is here! Try out:
  • Installation withgo get:
go get github.com/johnfercher/maroto/v2@v2.0.4
  • You can see the full v2 documentation here.
  • The v1 still exists in this branch, and you can see the doc here.

result

Contributing

Command Description Dependencies
make build Build project go
make test Run unit tests go
make fmt Format files gofmt, gofumpt and goimports
make lint Check files golangci-lint
make dod (Definition of Done) Format files and check files Same as make build, make test, make fmt and make lint
make install Install all dependencies go, curl and git
make examples Run all examples go
make mocks Generate mocks go and mockery
make docs Run docsify docs server local docsify
make godoc Run godoc server local godoc

Stargazers over time

Stargazers over time

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New is responsible for create a new instance of core.Maroto. 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 maroto instance.

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

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

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

func NewMetricsDecorator

func NewMetricsDecorator(inner core.Maroto) core.Maroto

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

Example

ExampleNewMetricsDecorator demonstrates how to create a maroto metrics decorator instance.

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

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

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

Types

type Maroto

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

func (*Maroto) AddPages

func (m *Maroto) 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, maroto will split that page in more than one.

Example

ExampleMaroto_AddPages demonstrates how to add a new page in maroto.

m := maroto.New()

p := page.New()
p.Add(code.NewBarRow(10, "barcode"))

m.AddPages(p)

// Do things and generate
Output:

func (*Maroto) AddRow

func (m *Maroto) 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, maroto will automatically add a new page. Maroto use the information of PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful area of a page.

Example

ExampleMaroto_AddRow demonstrates how to add a new row in maroto.

m := maroto.New()

m.AddRow(10, text.NewCol(12, "text"))

// Do things and generate
Output:

func (*Maroto) AddRows

func (m *Maroto) 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, maroto will automatically add a new page. Maroto use the information of PageSize, PageMargin, FooterSize and HeaderSize to calculate the useful area of a page.

Example

ExampleMaroto_AddRows demonstrates how to add new rows in maroto.

m := maroto.New()

m.AddRows(
	code.NewBarRow(12, "barcode"),
	text.NewRow(12, "text"),
)

// Do things and generate
Output:

func (*Maroto) FitlnCurrentPage

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

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

Example

ExampleMaroto_FitlnCurrentPage demonstrate how to check if the new line fits on the current page

m := maroto.New()

m.FitlnCurrentPage(12)

// Do things and generate
Output:

func (*Maroto) Generate

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

Generate is responsible to compute the component tree created by the usage of all other Maroto methods, and generate the PDF document.

Example

ExampleMaroto_Generate demonstrates how to generate a file.

m := maroto.New()

// Add rows, pages and etc.

doc, err := m.Generate()
if err != nil {
	log.Fatal(err)
}

// You can retrieve as Base64, Save file, Merge with another file or GetReport.
_ = doc.GetBytes()
Output:

func (*Maroto) GetStructure

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

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

Example

ExampleMarotoGetStruct demonstrates how to get maroto component tree

m := maroto.New()

m.AddRow(40, text.NewCol(12, "text"))

m.GetStructure()

// Do things and generate
Output:

func (*Maroto) RegisterFooter

func (m *Maroto) 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.

Example

ExampleMaroto_RegisterFooter demonstrates how to register a footer to me added in every new page. An error is returned if the area occupied by the footer is greater than the page area.

m := maroto.New()

err := m.RegisterFooter(
	code.NewBarRow(12, "barcode"),
	text.NewRow(12, "text"))
if err != nil {
	panic(err)
}

// Do things and generate
Output:

func (*Maroto) RegisterHeader

func (m *Maroto) 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.

Example

ExampleMaroto_RegisterHeader demonstrates how to register a header to me added in every new page. An error is returned if the area occupied by the header is greater than the page area.

m := maroto.New()

err := m.RegisterHeader(
	code.NewBarRow(12, "barcode"),
	text.NewRow(12, "text"))
if err != nil {
	panic(err)
}

// Do things and generate
Output:

type MetricsDecorator

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

func (*MetricsDecorator) AddPages

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

AddPages decorates the AddPages method of maroto instance.

func (*MetricsDecorator) AddRow

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

AddRow decorates the AddRow method of maroto instance.

func (*MetricsDecorator) AddRows

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

AddRows decorates the AddRows method of maroto instance.

func (*MetricsDecorator) FitlnCurrentPage

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

func (*MetricsDecorator) Generate

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

Generate decorates the Generate method of maroto instance.

func (*MetricsDecorator) GetStructure

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

GetStructure decorates the GetStructure method of maroto instance.

func (*MetricsDecorator) RegisterFooter

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

RegisterFooter decorates the RegisterFooter method of maroto instance.

func (*MetricsDecorator) RegisterHeader

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

RegisterHeader decorates the RegisterHeader method of maroto instance.

Directories

Path Synopsis
cmd
Package docs is the documentation of maroto lib.
Package docs is the documentation of maroto lib.
internal
nolint: dupl
pkg
Package pkg contains the public code of maroto.
Package pkg contains the public code of maroto.
components
Package components contains the public components of maroto.
Package components contains the public components of maroto.
components/code
Package code implements creation of Barcode, MatrixCode and QrCode.
Package code implements creation of Barcode, MatrixCode and QrCode.
components/col
Package col implements creation of columns.
Package col implements creation of columns.
components/image
Package image implements creation of images from file and bytes.
Package image implements creation of images from file and bytes.
components/line
Package line implements creation of lines.
Package line implements creation of lines.
components/list
Package list implements creation of lists (old tablelist).
Package list implements creation of lists (old tablelist).
components/page
Package page implements creation of pages.
Package page implements creation of pages.
components/row
Package row implements creation of rows.
Package row implements creation of rows.
components/signature
Package signature implements creation of signatures.
Package signature implements creation of signatures.
components/text
Package text implements creation of texts.
Package text implements creation of texts.
config
Package config implements custom configuration builder.
Package config implements custom configuration builder.
consts
Package consts contains the public constants of maroto.
Package consts contains the public constants of maroto.
consts/align
Package align contains all align types.
Package align contains all align types.
consts/border
Package border contains all border types.
Package border contains all border types.
consts/breakline
Package breakline contains all break line strategies.
Package breakline contains all break line strategies.
consts/extension
Package extension contains all image extensions.
Package extension contains all image extensions.
consts/fontfamily
Package fontfamily contains all default font families.
Package fontfamily contains all default font families.
consts/fontstyle
Package fontstyle contains all default font styles.
Package fontstyle contains all default font styles.
consts/linestyle
Package linestyle contains all line styles.
Package linestyle contains all line styles.
consts/orientation
Package orientation contains all orientations.
Package orientation contains all orientations.
consts/pagesize
Package pagesize contains all default page sizes.
Package pagesize contains all default page sizes.
consts/protection
Package protection contains all protection types.
Package protection contains all protection types.
consts/provider
Package provider contains all document generation providers.
Package provider contains all document generation providers.
core
Package core contains all core interfaces and basic implementations.
Package core contains all core interfaces and basic implementations.
core/entity
Package entity contains all core entities.
Package entity contains all core entities.
merge
Package merge implements PDF merge.
Package merge implements PDF merge.
metrics
Package metrics contains metrics models, constants and formatting.
Package metrics contains metrics models, constants and formatting.
props
Package props contain the public properties of maroto.
Package props contain the public properties of maroto.
repository
Package repository implements font repository.
Package repository implements font repository.
test
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