Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnferchermeli committed Mar 28, 2020
1 parent 8a9c2d9 commit 2b3c797
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 338 deletions.
178 changes: 126 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,99 +66,173 @@ with the code to generate the PDFs.

#### Code
```go
// Billing example
package main

import (
"fmt"
"github.com/johnfercher/maroto/pkg/color"
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"os"
"time"
)

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,
begin := time.Now()

darkGrayColor := getDarkGrayColor()
grayColor := getGrayColor()
whiteColor := color.NewWhite()
header := getHeader()
contents := getContents()

m := pdf.NewMaroto(consts.Portrait, consts.A4)
m.SetPageMargins(10, 15, 10)
//m.SetBorder(true)

m.RegisterHeader(func() {
m.Row(20, func() {
m.Col(3, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
m.Text("1000 Shipping Gopher Golang TN 3691234 GopherLand (GL)", props.Text{
Size: 12,
Top: 21,

m.ColSpace(6)

m.Col(3, func() {
m.Text("AnyCompany Name Inc. 851 Any Street Name, Suite 120, Any City, CA 45123.", props.Text{
Size: 8,
Align: consts.Right,
Extrapolate: false,
})
m.Text("Tel: 55 024 12345-1234", props.Text{
Top: 12,
Style: consts.BoldItalic,
Size: 8,
Align: consts.Right,
})
m.Text("www.mycompany.com", props.Text{
Top: 15,
Style: consts.BoldItalic,
Size: 8,
Align: consts.Right,
})
})
})
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.RegisterFooter(func() {
m.Row(20, func() {
m.Col(12, func() {
m.Text("Tel: 55 024 12345-1234", props.Text{
Top: 13,
Style: consts.BoldItalic,
Size: 8,
Align: consts.Left,
})
m.Text("www.mycompany.com", props.Text{
Top: 16,
Style: consts.BoldItalic,
Size: 8,
Align: consts.Left,
})
})
})
m.ColSpace()
m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", props.Rect{
Center: true,
Percent: 75,
})

m.Row(10, func() {
m.Col(12, func() {
m.Text("Invoice ABC123456789", props.Text{
Top: 3,
Style: consts.Bold,
Align: consts.Center,
})
})
})

m.Line(10)
m.SetBackgroundColor(darkGrayColor)

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,
m.Row(7, func() {
m.Col(3, func() {
m.Text("Transactions", props.Text{
Top: 1.5,
Size: 9,
Style: consts.Bold,
Align: consts.Center,
Top: 80,
})
})
m.ColSpace(9)
})

m.SetBorder(true)
m.SetBackgroundColor(whiteColor)

m.TableList(header, contents, props.TableList{
HeaderProp: props.TableListContent{
Size: 9,
GridSizes: []uint{3, 4, 2, 3},
},
ContentProp: props.TableListContent{
Size: 8,
GridSizes: []uint{3, 4, 2, 3},
},
Align: consts.Center,
AlternatedBackground: &grayColor,
HeaderContentSpace: 1,
Line: false,
})

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.Row(20, func() {
m.ColSpace(7)
m.Col(2, func() {
m.Text("Total:", props.Text{
Top: 5,
Style: consts.Bold,
Size: 8,
Align: consts.Right,
})
})
m.Col(func() {
m.Text("CA", props.Text{
Top: 30,
Size: 85,
m.Col(3, func() {
m.Text("R$ 2.567,00", props.Text{
Top: 5,
Style: consts.Bold,
Size: 8,
Align: consts.Center,
})
})
})

m.SetBorder(false)
m.Row(15, func() {
m.Col(6, func() {
_ = m.Barcode("5123.151231.512314.1251251.123215", props.Barcode{
Percent: 0,
Proportion: props.Proportion{
Width: 20,
Height: 2,
},
})
m.Text("5123.151231.512314.1251251.123215", props.Text{
Top: 12,
Family: "",
Style: consts.Bold,
Size: 9,
Align: consts.Center,
})
})
m.ColSpace(6)
})

err := m.OutputFileAndClose("internal/examples/pdfs/zpl.pdf")
err := m.OutputFileAndClose("internal/examples/pdfs/billing.pdf")
if err != nil {
fmt.Println("Could not save PDF:", err)
os.Exit(1)
}

end := time.Now()
fmt.Println(end.Sub(begin))
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The following Go Code generates a simple PDF file.
m := pdf.NewMaroto(consts.Portrait, consts.Letter)
m.Row(10, func() {
m.Col(func() {
m.Col(12, func() {
m.Text(props.Text{
Size: 18,
Style: consts.Bold,
Expand Down
99 changes: 56 additions & 43 deletions internal/examples/billing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ import (
func main() {
begin := time.Now()

darkGrayColor := color.Color{
Red: 144,
Green: 144,
Blue: 144,
}

grayColor := color.Color{
Red: 200,
Green: 200,
Blue: 200,
}

darkGrayColor := getDarkGrayColor()
grayColor := getGrayColor()
whiteColor := color.NewWhite()
header := getHeader()
contents := getContents()

m := pdf.NewMaroto(consts.Portrait, consts.A4)
m.SetPageMargins(10, 15, 10)
Expand Down Expand Up @@ -109,37 +101,6 @@ func main() {

m.SetBackgroundColor(whiteColor)

header := []string{"", "Product", "Quantity", "Price"}
contents := [][]string{
{"", "Swamp", "12", "R$ 4,00"},
{"", "Sorin, A Planeswalker", "4", "R$ 90,00"},
{"", "Tassa", "4", "R$ 30,00"},
{"", "Skinrender", "4", "R$ 9,00"},
{"", "Island", "12", "R$ 4,00"},
{"", "Mountain", "12", "R$ 4,00"},
{"", "Plain", "12", "R$ 4,00"},
{"", "Black Lotus", "1", "R$ 1.000,00"},
{"", "Time Walk", "1", "R$ 1.000,00"},
{"", "Emberclave", "4", "R$ 44,00"},
{"", "Anax", "4", "R$ 32,00"},
{"", "Murderous Rider", "4", "R$ 22,00"},
{"", "Gray Merchant of Asphodel", "4", "R$ 2,00"},
{"", "Ajani's Pridemate", "4", "R$ 2,00"},
{"", "Renan, Chatuba", "4", "R$ 19,00"},
{"", "Tymarett", "4", "R$ 13,00"},
{"", "Doom Blade", "4", "R$ 5,00"},
{"", "Dark Lord", "3", "R$ 7,00"},
{"", "Memory of Thanatos", "3", "R$ 32,00"},
{"", "Poring", "4", "R$ 1,00"},
{"", "Deviling", "4", "R$ 99,00"},
{"", "Seiya", "4", "R$ 45,00"},
{"", "Harry Potter", "4", "R$ 62,00"},
{"", "Goku", "4", "R$ 77,00"},
{"", "Phreoni", "4", "R$ 22,00"},
{"", "Katheryn High Wizard", "4", "R$ 25,00"},
{"", "Lord Seyren", "4", "R$ 55,00"},
}

m.TableList(header, contents, props.TableList{
HeaderProp: props.TableListContent{
Size: 9,
Expand Down Expand Up @@ -204,3 +165,55 @@ func main() {
end := time.Now()
fmt.Println(end.Sub(begin))
}

func getHeader() []string {
return []string{"", "Product", "Quantity", "Price"}
}

func getContents() [][]string {
return [][]string{
{"", "Swamp", "12", "R$ 4,00"},
{"", "Sorin, A Planeswalker", "4", "R$ 90,00"},
{"", "Tassa", "4", "R$ 30,00"},
{"", "Skinrender", "4", "R$ 9,00"},
{"", "Island", "12", "R$ 4,00"},
{"", "Mountain", "12", "R$ 4,00"},
{"", "Plain", "12", "R$ 4,00"},
{"", "Black Lotus", "1", "R$ 1.000,00"},
{"", "Time Walk", "1", "R$ 1.000,00"},
{"", "Emberclave", "4", "R$ 44,00"},
{"", "Anax", "4", "R$ 32,00"},
{"", "Murderous Rider", "4", "R$ 22,00"},
{"", "Gray Merchant of Asphodel", "4", "R$ 2,00"},
{"", "Ajani's Pridemate", "4", "R$ 2,00"},
{"", "Renan, Chatuba", "4", "R$ 19,00"},
{"", "Tymarett", "4", "R$ 13,00"},
{"", "Doom Blade", "4", "R$ 5,00"},
{"", "Dark Lord", "3", "R$ 7,00"},
{"", "Memory of Thanatos", "3", "R$ 32,00"},
{"", "Poring", "4", "R$ 1,00"},
{"", "Deviling", "4", "R$ 99,00"},
{"", "Seiya", "4", "R$ 45,00"},
{"", "Harry Potter", "4", "R$ 62,00"},
{"", "Goku", "4", "R$ 77,00"},
{"", "Phreoni", "4", "R$ 22,00"},
{"", "Katheryn High Wizard", "4", "R$ 25,00"},
{"", "Lord Seyren", "4", "R$ 55,00"},
}
}

func getDarkGrayColor() color.Color {
return color.Color{
Red: 144,
Green: 144,
Blue: 144,
}
}

func getGrayColor() color.Color {
return color.Color{
Red: 200,
Green: 200,
Blue: 200,
}
}
Binary file modified internal/examples/pdfs/billing.pdf
Binary file not shown.
Loading

0 comments on commit 2b3c797

Please sign in to comment.