Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert PDF to ZPL, Fix text side-effect update on cell #315

Merged
merged 8 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ always when a new page appear, in this case, a header may have many rows, lines
* With `go get`:

```bash
go get github.com/johnfercher/maroto/v2/[email protected].24
go get github.com/johnfercher/maroto/v2/[email protected].25
```


Expand Down
File renamed without changes.
120 changes: 120 additions & 0 deletions cmd/dev/zpl/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package main

import (
"encoding/base64"
"fmt"
"log"
"os"

"github.com/johnfercher/maroto/v2/pkg/components/code"
"github.com/johnfercher/maroto/v2/pkg/components/col"
"github.com/johnfercher/maroto/v2/pkg/components/image"
"github.com/johnfercher/maroto/v2/pkg/components/line"
"github.com/johnfercher/maroto/v2/pkg/components/text"
"github.com/johnfercher/maroto/v2/pkg/consts/align"
"github.com/johnfercher/maroto/v2/pkg/consts/documenttype"
"github.com/johnfercher/maroto/v2/pkg/consts/extension"
"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"

"github.com/johnfercher/maroto/v2/pkg"
"github.com/johnfercher/maroto/v2/pkg/config"
"github.com/johnfercher/maroto/v2/pkg/props"
)

func main() {
cfg := config.NewBuilder().
WithDimensions(101.6, 152.4).
Build()

mrt := pkg.NewMaroto(cfg)
m := pkg.NewMetricsDecorator(mrt)

byteSlices, err := os.ReadFile("docs/assets/images/frontpage.png")
if err != nil {
fmt.Println("Got error while opening file:", err)
os.Exit(1)
}
stringBase64 := base64.StdEncoding.EncodeToString(byteSlices)

m.AddRow(20,
image.NewFromBase64Col(4, stringBase64, extension.Png, props.Rect{
Center: true,
Percent: 80,
}),
col.New(8).Add(
text.New("Maroto V2", props.Text{
Size: 15,
Style: fontstyle.Bold,
}),
text.New("ZPL Generator", props.Text{
Top: 8,
Size: 10,
Style: fontstyle.Bold,
}),
text.New("Based On PDF", props.Text{
Top: 12,
Size: 10,
Style: fontstyle.Bold,
}),
),
)

m.AddRows(line.NewRow(5, props.Line{OffsetPercent: 50}))

m.AddRow(20,
col.New(8).Add(
text.New("Maroto V2", props.Text{
Left: 10,
Top: 3,
Align: align.Left,
}),
text.New("ZPL Generator", props.Text{
Left: 10,
Top: 8,
Align: align.Left,
}),
text.New("Based On PDF", props.Text{
Left: 10,
Top: 13,
Align: align.Left,
}),
),
code.NewQrCol(4, "qrcode", props.Rect{
Center: true,
}),
)

m.AddRows(line.NewRow(5, props.Line{OffsetPercent: 50}))

m.AddRows(code.NewBarRow(20, "code", props.Barcode{
Percent: 70,
Center: true,
}))

m.AddRows(text.NewRow(20, "code123"))

document, err := m.Generate()
if err != nil {
log.Fatal(err.Error())
}

err = document.Save("docs/assets/pdf/zplv2.pdf")
if err != nil {
log.Fatal(err.Error())
}

document, err = document.To(documenttype.ZPL)
if err != nil {
log.Fatal(err.Error())
}

err = document.Save("docs/assets/zpl/zplv2.zpl")
if err != nil {
log.Fatal(err.Error())
}

err = document.GetReport().Save("docs/assets/text/zplv2.txt")
if err != nil {
log.Fatal(err.Error())
}
}
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#template-engines) [![Branch](https://img.shields.io/badge/V2-Branch-pink)](https://github.com/johnfercher/maroto/tree/v2) [![Roadmap](https://img.shields.io/badge/V2-Roadmap-purple)](https://github.com/users/johnfercher/projects/1) [![Discussion](https://img.shields.io/badge/V2-Discussion-blue)](https://github.com/johnfercher/maroto/issues/257) [![Release Notes](https://img.shields.io/badge/Release-Notes-cyan)](https://github.com/johnfercher/maroto/releases) [![Visits Badge](https://badges.pufler.dev/visits/johnfercher/maroto)](https://badges.pufler.dev)

#### Maroto`v2.0.0-alpha.24`is here! Try out:
#### Maroto`v2.0.0-alpha.25`is here! Try out:

* Installation with`go get`:

```bash
go get github.com/johnfercher/maroto/v2/[email protected].24
go get github.com/johnfercher/maroto/v2/[email protected].25
```

The public API was completely redesigned with the aim of enhancing the
Expand All @@ -30,7 +30,7 @@ library in various aspects. The main objectives of`v2.0.0`are:
- Initially, the project will focus on defining a design that enables us to accomplish all objectives. Subsequently, we will begin incorporating all features from the old version, and finally, we will introduce the new features.

## Code Example
[filename](https://raw.githubusercontent.com/johnfercher/maroto/v2/cmd/dev/main.go ':include :type=code')
[filename](https://raw.githubusercontent.com/johnfercher/maroto/v2/cmd/dev/pdf/main.go ':include :type=code')

## PDF Generated
```pdf
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [Orientation](v2/features/orientation.md?id=orientation)
* [Page Number](v2/features/pagenumber.md?id=page-number)
* [Parallelism](v2/features/parallelism.md?id=parallelism)
* [PDF 2 ZPL](v2/features/pdf2zpl?id=pdf-2-zpl)
* [Protection](v2/features/protection.md?id=protection)
* [QR Code](v2/features/qrcode.md?id=qrcode)
* [Signature](v2/features/signature.md?id=signature)
Expand Down
120 changes: 120 additions & 0 deletions docs/assets/examples/pdf2zpl/v2/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package main

import (
"encoding/base64"
"fmt"
"log"
"os"

"github.com/johnfercher/maroto/v2/pkg/components/code"
"github.com/johnfercher/maroto/v2/pkg/components/col"
"github.com/johnfercher/maroto/v2/pkg/components/image"
"github.com/johnfercher/maroto/v2/pkg/components/line"
"github.com/johnfercher/maroto/v2/pkg/components/text"
"github.com/johnfercher/maroto/v2/pkg/consts/align"
"github.com/johnfercher/maroto/v2/pkg/consts/documenttype"
"github.com/johnfercher/maroto/v2/pkg/consts/extension"
"github.com/johnfercher/maroto/v2/pkg/consts/fontstyle"

"github.com/johnfercher/maroto/v2/pkg"
"github.com/johnfercher/maroto/v2/pkg/config"
"github.com/johnfercher/maroto/v2/pkg/props"
)

func main() {
cfg := config.NewBuilder().
WithDimensions(101.6, 152.4).
Build()

mrt := pkg.NewMaroto(cfg)
m := pkg.NewMetricsDecorator(mrt)

byteSlices, err := os.ReadFile("docs/assets/images/frontpage.png")
if err != nil {
fmt.Println("Got error while opening file:", err)
os.Exit(1)
}
stringBase64 := base64.StdEncoding.EncodeToString(byteSlices)

m.AddRow(20,
image.NewFromBase64Col(4, stringBase64, extension.Png, props.Rect{
Center: true,
Percent: 80,
}),
col.New(8).Add(
text.New("Maroto V2", props.Text{
Size: 15,
Style: fontstyle.Bold,
}),
text.New("ZPL Generator", props.Text{
Top: 8,
Size: 10,
Style: fontstyle.Bold,
}),
text.New("Based On PDF", props.Text{
Top: 12,
Size: 10,
Style: fontstyle.Bold,
}),
),
)

m.AddRows(line.NewRow(5, props.Line{OffsetPercent: 50}))

m.AddRow(20,
col.New(8).Add(
text.New("Maroto V2", props.Text{
Left: 10,
Top: 3,
Align: align.Left,
}),
text.New("ZPL Generator", props.Text{
Left: 10,
Top: 8,
Align: align.Left,
}),
text.New("Based On PDF", props.Text{
Left: 10,
Top: 13,
Align: align.Left,
}),
),
code.NewQrCol(4, "qrcode", props.Rect{
Center: true,
}),
)

m.AddRows(line.NewRow(5, props.Line{OffsetPercent: 50}))

m.AddRows(code.NewBarRow(20, "code", props.Barcode{
Percent: 70,
Center: true,
}))

m.AddRows(text.NewRow(20, "code123"))

document, err := m.Generate()
if err != nil {
log.Fatal(err.Error())
}

err = document.Save("docs/assets/pdf/zplv2.pdf")
if err != nil {
log.Fatal(err.Error())
}

document, err = document.To(documenttype.ZPL)
if err != nil {
log.Fatal(err.Error())
}

err = document.Save("docs/assets/zpl/zplv2.zpl")
if err != nil {
log.Fatal(err.Error())
}

err = document.GetReport().Save("docs/assets/text/zplv2.txt")
if err != nil {
log.Fatal(err.Error())
}
}
Loading