Skip to content

Commit

Permalink
Add Page
Browse files Browse the repository at this point in the history
  • Loading branch information
johnferchermeli committed May 16, 2020
1 parent 612b81c commit 073c859
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,37 @@ go get -u github.com/johnfercher/maroto
```

## Features

![result](internal/assets/images/diagram.png)

#### Grid System
* [Row](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Row)
* [Col](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Col)
* [ColSpace](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-ColSpace)
* [ColSpaces](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-ColSpaces)
* [Row](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Row)
* [Col](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Col)
* [ColSpace](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.ColSpace)
* [AddPage](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.AddPage)

#### Components To Use Inside a Col
* [Text w/ automatic new lines](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Text)
* [Signature](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Signature)
* Image ([From file](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-FileImage) or [Base64](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Base64Image))
* [QrCode](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#PdfMaroto.QrCode)
* [Barcode](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#PdfMaroto.Barcode)
* [Text w/ automatic new lines](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Text)
* [Signature](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Signature)
* Image ([From file](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.FileImage) or [Base64](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Base64Image))
* [QrCode](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.QrCode)
* [Barcode](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Barcode)

#### Components To Use Outside a Row
* [TableList](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-TableList)
* [Line](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Line)
* [TableList](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.TableList)
* [Line](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Line)

#### Components To Wrap Row, TableList and Line
* [RegisterHeader](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#PdfMaroto.RegisterHeader)
* [RegisterFooter](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#PdfMaroto.RegisterFooter)
* [RegisterHeader](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.RegisterHeader)
* [RegisterFooter](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.RegisterFooter)

#### Others
* [Properties](https://godoc.org/github.com/johnfercher/maroto/pkg/props): most of the components has properties which you can use to customize appearance and behavior.
* [SetBorder](https://godoc.org/github.com/johnfercher/maroto#PdfMaroto.SetDebugMode): Used to draw rectangles in every row and column
* [Properties](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/props?tab=doc): most of the components has properties which you can use to customize appearance and behavior.
* [SetBorder](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.SetBorder): Used to draw rectangles in every row and column
* [SetBackgroundColor](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.SetBackgroundColor): Used to change the background color of one cell.
* [SetPageMargins](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.SetPageMargins): Customize the page margins
* Automatic New Page: New pages are generated automatically when needed.
* 100% Unicode
* Save: You can [save on disk](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-OutputFileAndClose) or export to a [base64 string](https://godoc.org/github.com/johnfercher/maroto/pkg/pdf#example-PdfMaroto-Output)
* Save: You can [save on disk](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.OutputFileAndClose) or export to a [base64 string](https://pkg.go.dev/github.com/johnfercher/maroto/pkg/pdf?tab=doc#PdfMaroto.Output)

#### Roadmap
* Updated in [Issues](https://github.com/johnfercher/maroto/issues)
Expand Down
1 change: 0 additions & 1 deletion internal/examples/billing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func main() {

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

m.RegisterHeader(func() {
m.Row(20, func() {
Expand Down
Binary file modified internal/examples/pdfs/barcodegrid.pdf
Binary file not shown.
Binary file modified internal/examples/pdfs/billing.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.
8 changes: 2 additions & 6 deletions internal/examples/sample1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func main() {
},
})

m.AddPage()

m.Row(15, func() {
m.Col(12, func() {
m.Text(fmt.Sprintf("Medium Packages / %du.", len(mediumContent)), props.Text{
Expand Down Expand Up @@ -218,12 +220,6 @@ func getSmallContent() ([]string, [][]string) {
contents = append(contents, []string{"São Vicente", "Juiz de Fora", "R$ 35,00"})
contents = append(contents, []string{"Taubaté", "Rio de Janeiro", "R$ 82,00"})
contents = append(contents, []string{"Suzano", "Petrópolis", "R$ 62,00"})
contents = append(contents, []string{"Jundiaí", "Florianópolis", "R$ 21,00"})
contents = append(contents, []string{"Natal", "Jundiaí", "R$ 12,00"})
contents = append(contents, []string{"Niterói", "Itapevi", "R$ 21,00"})
contents = append(contents, []string{"São Paulo", "Rio de Janeiro", "R$ 31,00"})
contents = append(contents, []string{"São Carlos", "Petrópolis", "R$ 42,00"})
contents = append(contents, []string{"Florianópolis", "Osasco", "R$ 19,00"})

return header, contents
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (s *PdfMaroto) createColSpace(actualWidthPerCol float64) {
border = "1"
}

s.Pdf.CellFormat(actualWidthPerCol, s.rowHeight, "", border, 0.0, "C", !s.backgroundColor.IsWhite(), 0.0, "")
s.Pdf.CellFormat(actualWidthPerCol, s.rowHeight, "", border, 0, "C", !s.backgroundColor.IsWhite(), 0, "")
}

func (s *PdfMaroto) drawLastFooter() {
Expand Down
14 changes: 14 additions & 0 deletions pkg/pdf/pdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1845,3 +1845,17 @@ func TestPdfMaroto_GetPageMargins(t *testing.T) {
assert.Equal(t, 0.0, right)
assert.Equal(t, 0.0, bottom)
}

func TestPdfMaroto_AddPage(t *testing.T) {
// Arrange
pdf := basePdfTest(10.0, 10.0, 10.0)
m := newMarotoTest(pdf, nil, nil, nil, nil, nil, nil, nil)

// Act
m.AddPage()

// Assert
pdf.AssertCalled(t, "CellFormat", 80, 0, "", "", 0, "C", false, 0, "")
pdf.AssertCalled(t, "SetFillColor", 255, 255, 255)
pdf.AssertCalled(t, "Ln", 90.0)
}

0 comments on commit 073c859

Please sign in to comment.