maroto

package module
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 15 Imported by: 23

README

Maroto V2

GoDoc Go Report Card Mentioned in Awesome Go
CI Lint Codecov Visits Badge Stars 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.2.1 is here! Try out:
  • Installation withgo get:
go get github.com/johnfercher/maroto/v2@v2.2.1
  • 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.

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.

Output:

Types

type Maroto

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

func (*Maroto) AddAutoRow added in v2.1.0

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

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.

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.

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

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.

Output:

func (*Maroto) GetCurrentConfig added in v2.0.5

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

GetCurrentConfig is responsible for returning the current settings from the file

Example

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

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

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.

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.

Output:

type MetricsDecorator

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

func (*MetricsDecorator) AddAutoRow added in v2.1.0

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

AddRow decorates the AddRow method of maroto instance.

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

FitlnCurrentPage decoratess the FitlnCurrentPage method of maroto instance.

func (*MetricsDecorator) Generate

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

Generate decorates the Generate method of maroto instance.

func (*MetricsDecorator) GetCurrentConfig added in v2.0.5

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

GetCurrentConfig decorates the GetCurrentConfig 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
pkg
Package pkg contains the public code of maroto.
Package pkg contains the public code of maroto.

Jump to

Keyboard shortcuts

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