Skip to content

Commit

Permalink
keep
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfercher committed Sep 11, 2023
1 parent b22cfd1 commit 89d9882
Show file tree
Hide file tree
Showing 20 changed files with 452 additions and 121 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ always when a new page appear, in this case, a header may have many rows, lines
* With `go get`:

```bash
go get -u github.com/johnfercher/maroto/internal
go get -u github.com/johnfercher/pdf/internal
```

## Contributing
Expand Down
35 changes: 35 additions & 0 deletions cmd/v22/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/johnfercher/maroto/pkg/v22"
"github.com/johnfercher/maroto/pkg/v22/col"
"github.com/johnfercher/maroto/pkg/v22/image"
"github.com/johnfercher/maroto/pkg/v22/row"
)

func main() {
pdf := v22.NewDocument("pdfzin")

header := buildRow()
content := buildRow()
footer := buildRow()

pdf.Add(header, content, footer)

pdf.Render()
}

func buildRow() v22.Component {
row := row.New(20)

image := image.New("image1")

col1 := col.New(4)
col1.Add(image)

col2 := col.New(4)
col3 := col.New(4)

row.Add(col1, col2, col3)
return row
}
49 changes: 20 additions & 29 deletions docs/doc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/*
Package docs is the documentation of maroto. Maroto is a package which
Package docs is the documentation of pdf. Maroto is a package which
provide a simple way to generate PDF documents. The project is inspired
in Bootstrap and uses gofpdf. Simple and Fast
Features and Components
# Features and Components
- Grid system with rows and columns
Expand All @@ -24,43 +23,39 @@ Features and Components
Maroto has only gofpdf dependency. All tests pass on Linux and Mac.
Installation
# Installation
To install the package on your system, run
go get github.com/johnfercher/maroto
go get github.com/johnfercher/pdf
Later, to receive updates, run
go get -u -v github.com/johnfercher/maroto/...
go get -u -v github.com/johnfercher/pdf/...
Quick Start
# Quick Start
The following Go Code generates a simple PDF file.
m := pdf.NewMaroto(consts.Portrait, consts.Letter)
m := pdf.NewMaroto(consts.Portrait, consts.Letter)
m.Row(10, func() {
m.Col(12, func() {
m.Text(props.Text{
Size: 18,
Style: consts.Bold,
Align: consts.Center,
Top: 9,
m.AddRow(10, func() {
m.AddCol(12, func() {
m.Text(props.Text{
Size: 18,
Style: consts.Bold,
Align: consts.Center,
Top: 9,
})
})
})
})
m.OutputFileAndClose("maroto.pdf")
m.OutputFileAndClose("pdf.pdf")
See the functions in the maroto_test.go file (shown as examples in this
documentation) for more advanced PDF examples.
Conversion Notes
# Conversion Notes
This package is an high level API from gofpdf. The original API
names have been slightly adapted. And the package search to be
Expand All @@ -69,19 +64,15 @@ simpler to use.
The main contribution upside gofpdf is the grid system with
high level components.
License
# License
Maroto is released under the MIT License.
Acknowledgments
# Acknowledgments
This package’s Code and documentation are based on gofpdf.
Roadmap
# Roadmap
- Improve test coverage as reported by the coverage tool.
*/
Expand Down
18 changes: 15 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
module github.com/johnfercher/maroto

go 1.13
go 1.21.1

require (
github.com/boombuler/barcode v1.0.1
github.com/google/uuid v1.3.0
github.com/jung-kurt/gofpdf v1.16.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/johnfercher/go-tree v1.0.2 // indirect
github.com/phpdave11/gofpdf v1.4.2 // indirect
github.com/phpdave11/gofpdi v1.0.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.3.0
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a // indirect
golang.org/x/text v0.3.0 // indirect
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/johnfercher/go-tree v1.0.2 h1:9dZVcUjTAOpjC1Qemuxtl/xJRJjRpc3GOLOc/BOTyo0=
github.com/johnfercher/go-tree v1.0.2/go.mod h1:DUO6QkXIFh1K7jeGBIkLCZaeUgnkdQAsB64FDSoHswg=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.16.2 h1:jgbatWHfRlPYiK85qgevsZTHviWXKwB1TTiKdz5PtRc=
github.com/jung-kurt/gofpdf v1.16.2/go.mod h1:1hl7y57EsiPAkLbOwzpzqgx1A30nQCk/YmFV8S2vmK0=
Expand All @@ -23,8 +25,16 @@ github.com/ruudk/golang-pdf417 v0.0.0-20201230142125-a7e3863a1245/go.mod h1:pQAZ
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions internal/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSignature_AddSpaceFor_DefaultMargins(t *testing.T) {
math.On("GetWidthPerCol", mock.Anything).Return(50.0)

text := &mocks.Text{}
text.On("Add", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
text.On("Rows", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)

signature := internal.NewSignature(pdf, math, text)

Expand All @@ -40,8 +40,8 @@ func TestSignature_AddSpaceFor_DefaultMargins(t *testing.T) {
// Assert
pdf.AssertNumberOfCalls(t, "Line", 1)
pdf.AssertCalled(t, "Line", 19.0, 15.0, 13.0, 15.0)
text.AssertNumberOfCalls(t, "Add", 1)
text.AssertCalled(t, "Add", "label", internal.Cell{
text.AssertNumberOfCalls(t, "Rows", 1)
text.AssertCalled(t, "Rows", "label", internal.Cell{
5.0,
7.0,
2.0,
Expand All @@ -67,7 +67,7 @@ func TestSignature_AddSpaceFor_NotDefaultMargins(t *testing.T) {
math.On("GetWidthPerCol", mock.Anything).Return(50.0)

text := &mocks.Text{}
text.On("Add", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)
text.On("Rows", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything)

signature := internal.NewSignature(pdf, math, text)

Expand All @@ -77,8 +77,8 @@ func TestSignature_AddSpaceFor_NotDefaultMargins(t *testing.T) {
// Assert
pdf.AssertNumberOfCalls(t, "Line", 1)
pdf.AssertCalled(t, "Line", 26.0, 15.0, 23.0, 15.0)
text.AssertNumberOfCalls(t, "Add", 1)
text.AssertCalled(t, "Add", "label", internal.Cell{
text.AssertNumberOfCalls(t, "Rows", 1)
text.AssertCalled(t, "Rows", "label", internal.Cell{
2.0,
7.0,
5.0,
Expand Down
4 changes: 2 additions & 2 deletions internal/tablelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ type MarotoGridPart interface {
GetPageSize() (width float64, height float64)
GetPageMargins() (left float64, top float64, right float64, bottom float64)

// Outside Col/Row Components.
// Outside Col/AddRow Components.
Line(spaceHeight float64, line ...props.Line)

// Inside Col/Row Components.
// Inside Col/AddRow Components.
Text(text string, prop ...props.Text)
}

Expand Down
32 changes: 16 additions & 16 deletions internal/tablelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestTableList_Create_Happy(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("SetBackgroundColor", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
Expand All @@ -120,9 +120,9 @@ func TestTableList_Create_Happy(t *testing.T) {
font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertCalled(t, "AddRow", mock.Anything, mock.Anything)
marotoGrid.AssertCalled(t, "Line", mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertNumberOfCalls(t, "AddRow", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 20)
marotoGrid.AssertNotCalled(t, "SetBackgroundColor")
}
Expand All @@ -137,7 +137,7 @@ func TestTableList_Create_HappyWithBackgroundColor(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("SetBackgroundColor", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
Expand Down Expand Up @@ -165,8 +165,8 @@ func TestTableList_Create_HappyWithBackgroundColor(t *testing.T) {
font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertCalled(t, "AddRow", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "AddRow", 22)

marotoGrid.AssertNotCalled(t, "Line")

Expand All @@ -184,7 +184,7 @@ func TestTableList_Create_Happy_Without_Line(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
marotoGrid.On("GetPageSize").Return(200.0, 600.0)
Expand All @@ -204,8 +204,8 @@ func TestTableList_Create_Happy_Without_Line(t *testing.T) {
font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertCalled(t, "AddRow", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "AddRow", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 0)
}

Expand All @@ -219,7 +219,7 @@ func TestTableList_Create_HappyWithVerticalContentPadding(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
marotoGrid.On("GetPageSize").Return(200.0, 600.0)
Expand All @@ -241,8 +241,8 @@ func TestTableList_Create_HappyWithVerticalContentPadding(t *testing.T) {
font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertCalled(t, "AddRow", mock.Anything, mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "AddRow", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 0)
}

Expand All @@ -256,7 +256,7 @@ func TestTableList_Create_HappyWithCustomCellColor(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("SetBackgroundColor", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
Expand Down Expand Up @@ -298,9 +298,9 @@ func TestTableList_Create_HappyWithCustomCellColor(t *testing.T) {
font.AssertCalled(t, "GetFont")
font.AssertNumberOfCalls(t, "GetFont", 21)

marotoGrid.AssertCalled(t, "Row", mock.Anything, mock.Anything)
marotoGrid.AssertCalled(t, "AddRow", mock.Anything, mock.Anything)
marotoGrid.AssertCalled(t, "Line", mock.Anything)
marotoGrid.AssertNumberOfCalls(t, "Row", 22)
marotoGrid.AssertNumberOfCalls(t, "AddRow", 22)
marotoGrid.AssertNumberOfCalls(t, "Line", 20)
marotoGrid.AssertNotCalled(t, "SetBackgroundColor")
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestTableList_Create_WithLineProp(t *testing.T) {
font.On("GetScaleFactor").Return(1.5)

marotoGrid := &mocks.Maroto{}
marotoGrid.On("Row", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("AddRow", mock.Anything, mock.Anything).Return(nil)
marotoGrid.On("Line", mock.Anything).Return(nil)
marotoGrid.On("SetBackgroundColor", mock.Anything).Return(nil)
marotoGrid.On("GetPageMargins").Return(10.0, 10.0, 10.0, 10.0)
Expand Down
Loading

0 comments on commit 89d9882

Please sign in to comment.