README ¶
Maroto V2
A Maroto way to create PDFs. Maroto is inspired in Bootstrap and uses Gofpdf. Fast and simple.
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 with
go 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.
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
Documentation ¶
Index ¶
- func New(cfgs ...*entity.Config) core.Maroto
- func NewMetricsDecorator(inner core.Maroto) core.Maroto
- type Maroto
- func (m *Maroto) AddAutoRow(cols ...core.Col) core.Row
- func (m *Maroto) AddPages(pages ...core.Page)
- func (m *Maroto) AddRow(rowHeight float64, cols ...core.Col) core.Row
- func (m *Maroto) AddRows(rows ...core.Row)
- func (m *Maroto) FitlnCurrentPage(heightNewLine float64) bool
- func (m *Maroto) Generate() (core.Document, error)
- func (m *Maroto) GetCurrentConfig() *entity.Config
- func (m *Maroto) GetStructure() *node.Node[core.Structure]
- func (m *Maroto) RegisterFooter(rows ...core.Row) error
- func (m *Maroto) RegisterHeader(rows ...core.Row) error
- type MetricsDecorator
- func (m *MetricsDecorator) AddAutoRow(cols ...core.Col) core.Row
- func (m *MetricsDecorator) AddPages(pages ...core.Page)
- func (m *MetricsDecorator) AddRow(rowHeight float64, cols ...core.Col) core.Row
- func (m *MetricsDecorator) AddRows(rows ...core.Row)
- func (m *MetricsDecorator) FitlnCurrentPage(heightNewLine float64) bool
- func (m *MetricsDecorator) Generate() (core.Document, error)
- func (m *MetricsDecorator) GetCurrentConfig() *entity.Config
- func (m *MetricsDecorator) GetStructure() *node.Node[core.Structure]
- func (m *MetricsDecorator) RegisterFooter(rows ...core.Row) error
- func (m *MetricsDecorator) RegisterHeader(rows ...core.Row) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Maroto ¶
type Maroto struct {
// contains filtered or unexported fields
}
func (*Maroto) AddAutoRow ¶ added in v2.1.0
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 (*Maroto) RegisterHeader ¶
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) 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
|
|
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. |