Skip to content

Commit

Permalink
Merge pull request #120 from johnfercher/release/20-12-2019
Browse files Browse the repository at this point in the history
release/20-12-2019
  • Loading branch information
johnfercher authored Dec 20, 2019
2 parents 51992ea + b3c6876 commit b40e86a
Show file tree
Hide file tree
Showing 24 changed files with 902 additions and 351 deletions.
175 changes: 55 additions & 120 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,161 +69,96 @@ with the code to generate the PDFs.
package main

import (
"encoding/base64"
"fmt"
"github.com/johnfercher/maroto/pkg/consts"
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"io/ioutil"
"os"
)

func main() {
m := pdf.NewMaroto(consts.Portrait, consts.A4)
//m.SetBorder(true)
m := pdf.NewMaroto(consts.Portrait, consts.Letter)

byteSlices, _ := ioutil.ReadFile("internal/assets/images/biplane.jpg")

base64 := base64.StdEncoding.EncodeToString(byteSlices)

headerSmall, smallContent := getSmallContent()
headerMedium, mediumContent := getMediumContent()

m.RegisterHeader(func() {

m.Row(20, func() {
m.Col(func() {
m.Base64Image(base64, consts.Jpg, props.Rect{
Percent: 70,
})
})

m.ColSpaces(2)

m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", props.Rect{
Percent: 75,
})
})

m.Col(func() {
id := "https://github.com/johnfercher/maroto"
_ = m.Barcode(id, props.Barcode{
Proportion: props.Proportion{50, 10},
Percent: 75,
})
m.Text(id, props.Text{
Size: 7,
Align: consts.Center,
Top: 16,
})
m.Row(40, func() {
m.Col(func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})

m.Line(1.0)

m.Row(12, func() {
m.Col(func() {
m.FileImage("internal/assets/images/gopherbw.png")
m.Col(func() {
m.Text("Gopher International Shipping, Inc.", props.Text{
Top: 15,
Size: 20,
Extrapolate: true,
})

m.ColSpace()

m.Col(func() {
m.Text("Packages Report: Daily", props.Text{
Top: 4,
})
m.Text("Type: Small, Medium", props.Text{
Top: 10,
})
m.Text("1000 Shipping Gopher Golang TN 3691234 GopherLand (GL)", props.Text{
Size: 12,
Top: 21,
})
})
m.ColSpace()
})

m.ColSpace()
m.Line(10)

m.Col(func() {
m.Text("20/07/1994", props.Text{
Size: 10,
Style: consts.BoldItalic,
Top: 7.5,
Family: consts.Helvetica,
})
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.Line(1.0)

m.Row(22, func() {
m.Col(func() {
m.Text(fmt.Sprintf("Small: %d, Medium %d", len(smallContent), len(mediumContent)), props.Text{
Size: 15,
Style: consts.Bold,
Align: consts.Center,
Top: 9,
})
m.Text("Brasil / São Paulo", props.Text{
Size: 12,
Align: consts.Center,
Top: 17,
})
m.ColSpace()
m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", props.Rect{
Center: true,
Percent: 75,
})
})

m.Line(1.0)

})

m.RegisterFooter(func() {
m.Row(40, func() {
m.Col(func() {
m.Signature("Signature 1", props.Font{
Family: consts.Courier,
Style: consts.BoldItalic,
Size: 9,
})
})
m.Line(10)

m.Col(func() {
m.Signature("Signature 2")
m.Row(100, func() {
m.Col(func() {
_ = m.Barcode("https://github.com/johnfercher/maroto", props.Barcode{
Center: true,
Percent: 70,
})

m.Col(func() {
m.Signature("Signature 3")
m.Text("https://github.com/johnfercher/maroto", props.Text{
Size: 20,
Align: consts.Center,
Top: 80,
})
})
})

m.Row(15, func() {
m.SetBorder(true)

m.Row(40, func() {
m.Col(func() {
m.Text("Small Packages / 39u.", props.Text{
Top: 8,
Style: consts.Bold,
m.Text("CODE: 123412351645231245564 DATE: 20-07-1994 20:20:33", props.Text{
Size: 15,
Top: 19,
})
})
})

m.TableList(headerSmall, smallContent)

m.Row(15, func() {
m.Col(func() {
m.Text("Medium Packages / 22u.", props.Text{
Top: 8,
Style: consts.Bold,
m.Text("CA", props.Text{
Top: 30,
Size: 85,
Align: consts.Center,
})
})
})

m.TableList(headerMedium, mediumContent, props.TableList{
Align: consts.Center,
HeaderProp: props.Font{
Family: consts.Courier,
Style: consts.BoldItalic,
},
ContentProp: props.Font{
Family: consts.Courier,
Style: consts.Italic,
},
})
m.SetBorder(false)

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

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
github.com/boombuler/barcode v1.0.0
github.com/gojp/goreportcard v0.0.0-20191001233754-41818f5fd295 // indirect
github.com/google/uuid v1.1.1
github.com/jung-kurt/gofpdf v1.4.2
github.com/pkg/errors v0.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gojp/goreportcard v0.0.0-20191001233754-41818f5fd295 h1:bxKAVMPMl+mdSoSbVPNExWq/ix0G2WX9h5QyAWtjAoY=
github.com/gojp/goreportcard v0.0.0-20191001233754-41818f5fd295/go.mod h1:/DA2Xpp+OaR3EHafQSnT9SKOfbG2NPQR/qp6Qr8AgIw=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
Expand Down
12 changes: 9 additions & 3 deletions internal/examples/certificate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"os"
"time"
)

func main() {
begin := time.Now()
m := pdf.NewMaroto(consts.Landscape, consts.A4)
//m.SetBorder(true)

Expand Down Expand Up @@ -39,9 +41,10 @@ func main() {
m.Col(func() {
text := "Lorem Ipsum is simply dummy textá of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
m.Text(text, props.Text{
Size: 13,
Align: consts.Center,
Top: 60,
Size: 13,
Align: consts.Center,
Top: 60,
VerticalPadding: 2.0,
})
})
})
Expand All @@ -63,4 +66,7 @@ func main() {
fmt.Println("Could not save PDF:", err)
os.Exit(1)
}

end := time.Now()
fmt.Println(end.Sub(begin))
}
Binary file modified internal/examples/pdfs/certificate.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/sample1.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/zpl.pdf
Binary file not shown.
10 changes: 8 additions & 2 deletions internal/examples/sample1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/johnfercher/maroto/pkg/props"
"io/ioutil"
"os"
"time"
)

func main() {
begin := time.Now()
m := pdf.NewMaroto(consts.Portrait, consts.A4)
//m.SetBorder(true)

Expand Down Expand Up @@ -46,6 +48,7 @@ func main() {
m.Col(func() {
id := "https://github.com/johnfercher/maroto"
_ = m.Barcode(id, props.Barcode{
Center: true,
Proportion: props.Proportion{Width: 50, Height: 10},
Percent: 75,
})
Expand All @@ -61,7 +64,7 @@ func main() {

m.Row(12, func() {
m.Col(func() {
_ = m.FileImage("internal/assets/images/goherbw.png", props.Rect{
_ = m.FileImage("internal/assets/images/gopherbw.png", props.Rect{
Center: true,
})
})
Expand Down Expand Up @@ -168,6 +171,9 @@ func main() {
fmt.Println("Could not save PDF:", err)
os.Exit(1)
}

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

func getSmallContent() ([]string, [][]string) {
Expand All @@ -176,7 +182,7 @@ func getSmallContent() ([]string, [][]string) {
contents := [][]string{}
contents = append(contents, []string{"São Paulo", "Rio de Janeiro", "", "R$ 20,00"})
contents = append(contents, []string{"São Carlos", "Petrópolis", "", "R$ 25,00"})
contents = append(contents, []string{"Florianópolis", "Osasco", "", "R$ 20,00"})
contents = append(contents, []string{"São José do Vale do Rio Preto", "Osasco", "", "R$ 20,00"})
contents = append(contents, []string{"Osasco", "São Paulo", "", "R$ 5,00"})
contents = append(contents, []string{"Congonhas", "Fortaleza", "", "R$ 100,00"})
contents = append(contents, []string{"Natal", "Santo André", "", "R$ 200,00"})
Expand Down
7 changes: 7 additions & 0 deletions internal/examples/zpl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"github.com/johnfercher/maroto/pkg/pdf"
"github.com/johnfercher/maroto/pkg/props"
"os"
"time"
)

func main() {
begin := time.Now()
m := pdf.NewMaroto(consts.Portrait, consts.Letter)
//m.SetBorder(true)

Expand Down Expand Up @@ -45,6 +47,7 @@ func main() {
m.ColSpace()
m.Col(func() {
m.QrCode("https://github.com/johnfercher/maroto", props.Rect{
Center: true,
Percent: 75,
})
})
Expand All @@ -55,6 +58,7 @@ func main() {
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{
Expand Down Expand Up @@ -90,4 +94,7 @@ func main() {
fmt.Println("Could not save PDF:", err)
os.Exit(1)
}

end := time.Now()
fmt.Println(end.Sub(begin))
}
16 changes: 12 additions & 4 deletions internal/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ type Font interface {
GetStyle() consts.Style
GetSize() float64
GetFont() (consts.Family, consts.Style, float64)
GetScaleFactor() (scaleFactor float64)
}

type font struct {
pdf gofpdf.Pdf
size float64
family consts.Family
style consts.Style
pdf gofpdf.Pdf
size float64
family consts.Family
style consts.Style
scaleFactor float64
}

// NewFont create a Font
Expand All @@ -31,6 +33,7 @@ func NewFont(pdf gofpdf.Pdf, size float64, family consts.Family, style consts.St
size,
family,
style,
72.0 / 25.4, // Value defined inside gofpdf constructor
}
}

Expand Down Expand Up @@ -82,3 +85,8 @@ func (s *font) SetFont(family consts.Family, style consts.Style, size float64) {

s.pdf.SetFont(string(s.family), string(s.style), s.size)
}

// GetScaleFactor retrieve the scale factor defined in the instantiation of gofpdf
func (s *font) GetScaleFactor() (scaleFactor float64) {
return s.scaleFactor
}
Loading

0 comments on commit b40e86a

Please sign in to comment.