Skip to content

Commit

Permalink
Add width parameter in col
Browse files Browse the repository at this point in the history
* Width parameter works like bootstrap
* Adapt Image to work with the new version
  • Loading branch information
johnferchermeli committed Mar 23, 2020
1 parent 10c95da commit b0c8c39
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 193 deletions.
14 changes: 7 additions & 7 deletions internal/examples/certificate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ func main() {
//m.SetBorder(true)

m.Row(20, func() {
m.Col(func() {
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Percent: 88,
Center: true,
})
})
m.Col(func() {
m.Col(4, func() {
m.Text("Golang Certificate", props.Text{
Top: 12,
Align: consts.Center,
Size: 20,
Style: consts.BoldItalic,
})
})
m.Col(func() {
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Percent: 90,
Center: true,
Expand All @@ -38,7 +38,7 @@ func main() {
})

m.Row(130, func() {
m.Col(func() {
m.Col(12, 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,
Expand All @@ -50,13 +50,13 @@ func main() {
})

m.Row(25, func() {
m.Col(func() {
m.Col(4, func() {
m.Signature("Gopher Senior")
})
m.Col(func() {
m.Col(4, func() {
m.Signature("Gopheroid")
})
m.Col(func() {
m.Col(4, func() {
m.Signature("Sign Here")
})
})
Expand Down
147 changes: 147 additions & 0 deletions internal/examples/imagegrid/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package main

import (
"fmt"
"github.com/johnfercher/maroto/pkg/consts"
"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)

m.Row(40, func() {
m.Col(2, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
m.Col(6, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
})

m.Row(40, func() {
m.Col(2, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: false,
Percent: 50,
Left: 10,
})
})
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: false,
Percent: 50,
Top: 10,
})
})
m.Col(6, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: false,
Percent: 50,
Left: 15,
Top: 15,
})
})
})

m.Row(40, func() {
m.Col(8, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/biplane.jpg", props.Rect{
Center: true,
Percent: 80,
})
})
})

m.Row(40, func() {
m.Col(6, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: false,
Percent: 80,
Top: 5,
Left: 10,
})
})
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: false,
Percent: 80,
Top: 5,
})
})
m.Col(2, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: false,
Percent: 80,
Left: 5,
})
})
})

m.Row(40, func() {
m.Col(6, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: true,
Percent: 50,
})
})
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: true,
Percent: 50,
})
})
m.Col(2, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: true,
Percent: 50,
})
})
})

m.Row(40, func() {
m.Col(4, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: true,
Percent: 80,
})
})
m.Col(8, func() {
_ = m.FileImage("internal/assets/images/frontpage.png", props.Rect{
Center: true,
Percent: 80,
})
})
})

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

end := time.Now()
fmt.Println(end.Sub(begin))
}
Binary file added internal/examples/pdfs/imagegrid.pdf
Binary file not shown.
Binary file added internal/examples/pdfs/textgrid.pdf
Binary file not shown.
30 changes: 15 additions & 15 deletions internal/examples/sample1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ func main() {

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

m.ColSpaces(2)
m.ColSpace(3)

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

m.Col(func() {
m.Col(3, func() {
id := "https://github.com/johnfercher/maroto"
_ = m.Barcode(id, props.Barcode{
Center: true,
Expand All @@ -64,15 +64,15 @@ func main() {
m.Line(1.0)

m.Row(12, func() {
m.Col(func() {
m.Col(0, func() {
_ = m.FileImage("internal/assets/images/gopherbw.png", props.Rect{
Center: true,
})
})

m.ColSpace()
m.ColSpace(0)

m.Col(func() {
m.Col(0, func() {
m.Text("Packages Report: Daily", props.Text{
Top: 4,
})
Expand All @@ -81,9 +81,9 @@ func main() {
})
})

m.ColSpace()
m.ColSpace(0)

m.Col(func() {
m.Col(0, func() {
m.Text("20/07/1994", props.Text{
Size: 10,
Style: consts.BoldItalic,
Expand All @@ -96,7 +96,7 @@ func main() {
m.Line(1.0)

m.Row(22, func() {
m.Col(func() {
m.Col(0, func() {
m.Text(fmt.Sprintf("Small: %d, Medium %d", len(smallContent), len(mediumContent)), props.Text{
Size: 15,
Style: consts.Bold,
Expand All @@ -117,26 +117,26 @@ func main() {

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

m.Col(func() {
m.Col(4, func() {
m.Signature("Signature 2")
})

m.Col(func() {
m.Col(4, func() {
m.Signature("Signature 3")
})
})
})

m.Row(15, func() {
m.Col(func() {
m.Col(12, func() {
m.Text("Small Packages / 39u.", props.Text{
Top: 8,
Style: consts.Bold,
Expand All @@ -153,7 +153,7 @@ func main() {
})

m.Row(15, func() {
m.Col(func() {
m.Col(12, func() {
m.Text("Medium Packages / 22u.", props.Text{
Top: 8,
Style: consts.Bold,
Expand Down
36 changes: 36 additions & 0 deletions internal/examples/textgrid/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

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

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

m.Row(40, func() {
m.Col(2, func() {
m.Text("Any Text")
})
/*m.Col(4, func() {
m.Text("Any Text2")
})
m.Col(6, func() {
m.Text( "Any Text3")
})*/
})

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

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

0 comments on commit b0c8c39

Please sign in to comment.