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.
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.
- With
go get
:
go get -u github.com/johnfercher/maroto
- Properties: most of the components has properties which you can use to customize appearance and behavior.
- SetBorder: Used to draw rectangles in every row and column
- Automatic New Page: New pages are generated automatically when needed.
- 100% Unicode
- Save: You can save on disk or export to a base64 string
- Updated in Issues
In the PDFs folder there are the PDFs generated using Maroto, and in the examples folder there are subfolders with the code to generate the PDFs.
package main
import (
"fmt"
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"os"
)
func main() {
m := pdf.NewMaroto(consts.Portrait, consts.Letter)
m.Row(40, func() {
m.Col(func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
m.Col(func() {
m.Text("Gopher International Shipping, Inc.", props.Text{
Top: 15,
Size: 20,
Extrapolate: true,
})
m.Text("1000 Shipping Gopher Golang TN 3691234 GopherLand (GL)", props.Text{
Size: 12,
Top: 21,
})
})
m.ColSpace()
})
m.Line(10)
m.Row(40, func() {
m.Col(func() {
m.Text("João Sant'Ana 100 Main Street Stringfield TN 39021 United Stats (USA)", props.Text{
Size: 15,
Top: 14,
})
})
m.ColSpace()
m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", props.Rect{
Center: true,
Percent: 75,
})
})
})
m.Line(10)
m.Row(100, func() {
m.Col(func() {
_ = m.Barcode("https://github.com/johnfercher/maroto", props.Barcode{
Center: true,
Percent: 70,
})
m.Text("https://github.com/johnfercher/maroto", props.Text{
Size: 20,
Align: consts.Center,
Top: 80,
})
})
})
m.SetBorder(true)
m.Row(40, func() {
m.Col(func() {
m.Text("CODE: 123412351645231245564 DATE: 20-07-1994 20:20:33", props.Text{
Size: 15,
Top: 19,
})
})
m.Col(func() {
m.Text("CA", props.Text{
Top: 30,
Size: 85,
Align: consts.Center,
})
})
})
m.SetBorder(false)
err := m.OutputFileAndClose("internal/examples/pdfs/zpl.pdf")
if err != nil {
fmt.Println("Could not save PDF:", err)
os.Exit(1)
}
}