-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add main abstractions (Maroto, Node, Component, Page, Row, Col) * Add metrics decorator (MarotoMetrified, Metrics) * Add GetStructure to unit test structure (using go-tree) * Maroto computing pages to add on every row add * Create Provider abstraction to decouple maroto from gofpdf * Create a HTMLProvider to create HTML to prove that the abstraction work with other output * Maroto now use Cell as coordination * V2 already calling all maroto features, but we need to validate that everything is working * Image is validated by example example/imagegrid/v2 * Change behavior when can´t do an operation in gofpdf, now we are adding a message in the pdf * Fixed a behavior on image package where it didn´t follow the cell rule. * Using page size from maroto instead of gofpdf to decouple from gofpdf * Define component type to facilitate unit testing *
- Loading branch information
1 parent
300a3e8
commit c2310d0
Showing
42 changed files
with
7,962 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"github.com/johnfercher/maroto/pkg/consts" | ||
"github.com/johnfercher/maroto/pkg/props" | ||
"github.com/johnfercher/maroto/pkg/v2" | ||
"github.com/johnfercher/maroto/pkg/v2/code/barcode" | ||
"github.com/johnfercher/maroto/pkg/v2/code/matrixcode" | ||
"github.com/johnfercher/maroto/pkg/v2/code/qrcode" | ||
"github.com/johnfercher/maroto/pkg/v2/col" | ||
"github.com/johnfercher/maroto/pkg/v2/domain" | ||
"github.com/johnfercher/maroto/pkg/v2/image" | ||
"github.com/johnfercher/maroto/pkg/v2/providers" | ||
"github.com/johnfercher/maroto/pkg/v2/row" | ||
"github.com/johnfercher/maroto/pkg/v2/signature" | ||
"github.com/johnfercher/maroto/pkg/v2/size" | ||
"github.com/johnfercher/maroto/pkg/v2/text" | ||
"log" | ||
"os" | ||
) | ||
|
||
func main() { | ||
pageSize := size.A4 | ||
pdf := buildMarotoPDF(pageSize) | ||
html := buildMarotoHTML(pageSize) | ||
|
||
gen(pdf) | ||
gen(html) | ||
} | ||
|
||
func buildMarotoPDF(pageSize size.PageSize) domain.MarotoMetrified { | ||
provider := providers.NewGofpdf(pageSize) | ||
m := v2.NewMaroto(provider, "v2.pdf") | ||
return v2.NewMarotoMetrified(m) | ||
} | ||
|
||
func buildMarotoHTML(pageSize size.PageSize) domain.MarotoMetrified { | ||
provider := providers.NewHTML(pageSize) | ||
m := v2.NewMaroto(provider, "v2.html") | ||
return v2.NewMarotoMetrified(m) | ||
} | ||
|
||
func gen(m domain.MarotoMetrified) { | ||
m.Add(buildCodesRow(), buildImagesRow(), buildTextsRow()) | ||
m.Add(buildCodesRow(), buildImagesRow(), buildTextsRow()) | ||
m.Add(buildCodesRow(), buildImagesRow(), buildTextsRow()) | ||
|
||
report, err := m.GenerateWithReport() | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
||
report.Print() | ||
} | ||
|
||
func buildCodesRow() domain.Row { | ||
r := row.New(70) | ||
|
||
col1 := col.New(4) | ||
col1.Add(barcode.New("barcode")) | ||
|
||
col2 := col.New(4) | ||
col2.Add(qrcode.New("qrcode")) | ||
|
||
col3 := col.New(4) | ||
col3.Add(matrixcode.New("matrixcode")) | ||
|
||
r.Add(col1, col2, col3) | ||
return r | ||
} | ||
|
||
func buildImagesRow() domain.Row { | ||
row := row.New(70) | ||
|
||
col1 := col.New(6) | ||
col1.Add(image.NewFromFile("internal/assets/images/biplane.jpg")) | ||
|
||
byteSlices, err := os.ReadFile("internal/assets/images/gopherbw.png") | ||
if err != nil { | ||
fmt.Println("Got error while opening file:", err) | ||
os.Exit(1) | ||
} | ||
stringBase64 := base64.StdEncoding.EncodeToString(byteSlices) | ||
col2 := col.New(6) | ||
col2.Add(image.NewFromBase64(stringBase64, consts.Png)) | ||
|
||
row.Add(col1, col2) | ||
|
||
return row | ||
} | ||
|
||
func buildTextsRow() domain.Row { | ||
row := row.New(70) | ||
|
||
colText := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac condimentum sem." | ||
col1 := col.New(6) | ||
col1.Add(text.New(colText, props.Text{ | ||
Align: consts.Center, | ||
})) | ||
|
||
col2 := col.New(6) | ||
col2.Add(signature.New("Fulano de Tal", props.Font{ | ||
Style: consts.Italic, | ||
Size: 20, | ||
Family: consts.Courier, | ||
})) | ||
|
||
row.Add(col1, col2) | ||
|
||
return row | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
module github.com/johnfercher/maroto | ||
|
||
go 1.13 | ||
go 1.21.1 | ||
|
||
require ( | ||
github.com/boombuler/barcode v1.0.1 | ||
github.com/f-amaral/go-async v0.1.1 | ||
github.com/google/uuid v1.3.0 | ||
github.com/johnfercher/go-tree v1.0.3 | ||
github.com/jung-kurt/gofpdf v1.16.2 | ||
github.com/pdfcpu/pdfcpu v0.5.0 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/hhrutter/lzw v1.0.0 // indirect | ||
github.com/hhrutter/tiff v1.0.1 // indirect | ||
github.com/mattn/go-runewidth v0.0.15 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rivo/uniseg v0.4.4 // 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.11.0 // indirect | ||
golang.org/x/net v0.15.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.