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
- With
dep
:
dep ensure -add github.com/johnfercher/maroto
-
Grid System
-
Components To Use Inside a Col
-
Components To Use Outside a Row
-
Components To Wrap Row, TableList and Line
-
Properties: most of the components has properties which you can use to customize appearance and behavior.
-
DebugMode: 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
TODO
- RegisterFooter
- Increase Code Coverage
- Create a custom mock with better assertions
Here is the pdf generated.
func main() {
m := maroto.NewMaroto(maroto.Portrait, maroto.A4)
//m.SetDebugMode(true)
byteSlices, _ := ioutil.ReadFile("assets/images/gopher2.png")
base64 := base64.StdEncoding.EncodeToString(byteSlices)
header, contents := getContents()
m.RegisterHeader(func() {
// Image, Barcode and QrCode
m.Row(20, func() {
m.Col(func() {
m.Base64Image(base64, maroto.Png, &maroto.RectProp{
Percent: 85,
})
})
m.ColSpaces(2)
m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", &maroto.RectProp{
Percent: 75,
})
})
m.Col(func() {
id := "123456789"
_ = m.Barcode(id, &maroto.RectProp{
Percent: 70,
})
m.Text(id, &maroto.TextProp{
Size: 8,
Align: maroto.Center,
Top: 17,
})
})
})
m.Line(1.0)
// Image and Old License
m.Row(12, func() {
m.Col(func() {
m.FileImage("assets/images/gopher1.jpg", nil)
})
m.ColSpace()
m.Col(func() {
m.Text("PDFGenerator: Maroto", &maroto.TextProp{
Top: 4,
})
m.Text("Type: Easy & Fast", &maroto.TextProp{
Top: 10,
})
})
m.ColSpace()
m.Col(func() {
m.Text("GPL3", &maroto.TextProp{
Size: 16,
Style: maroto.Bold,
Top: 8,
})
})
})
m.Line(1.0)
// Features
m.Row(22, func() {
m.Col(func() {
m.Text("Grid System", &maroto.TextProp{
Size: 18,
Style: maroto.Bold,
Align: maroto.Center,
Top: 9,
})
m.Text("Bootstrap Like + Úñîçòdë", &maroto.TextProp{
Size: 12,
Align: maroto.Center,
Top: 17,
})
})
})
m.Line(1.0)
})
m.TableList(header, contents, nil)
// Signatures
m.Row(30, func() {
m.Col(func() {
m.Signature("Signature 1", nil)
})
m.Col(func() {
m.Signature("Signature 2", nil)
})
m.Col(func() {
m.Signature("Signature 3", nil)
})
})
_ = m.OutputFileAndClose("maroto.pdf")
}