Add 2of5 and pdf417

This commit is contained in:
Fred Boniface
2023-09-01 22:14:11 +01:00
parent f1c8eb82b8
commit d236acb2d7
9 changed files with 146 additions and 64 deletions

16
generation/2of5.go Normal file
View File

@@ -0,0 +1,16 @@
package generation
import (
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/twooffive"
)
func generate2of5(parameters Parameters) (barcode.Barcode, error) {
barcode, err := twooffive.Encode(parameters.Content, false)
if err != nil {
fmt.Println("Error creating Barcode", err)
}
return barcode, err
}

View File

@@ -0,0 +1,16 @@
package generation
import (
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/twooffive"
)
func generate2of5Interleaved(parameters Parameters) (barcode.Barcode, error) {
barcode, err := twooffive.Encode(parameters.Content, true)
if err != nil {
fmt.Println("Error creating Barcode", err)
}
return barcode, err
}

View File

@@ -8,9 +8,9 @@ import (
)
func generateCodabar(parameters Parameters) (barcode.Barcode, error) {
codabar, err := codabar.Encode(parameters.Content)
codabarItem, err := codabar.Encode(parameters.Content)
if err != nil {
fmt.Println("Error creating Barcode", err)
}
return codabar, err
return codabarItem, err
}

View File

@@ -23,6 +23,12 @@ func Generate(parameters Parameters) (barcode.Barcode, error) {
barcode_content, err = generateQr(parameters)
case Datamatrix:
barcode_content, err = generateDatamatrix(parameters)
case PDF417:
barcode_content, err = generatePDF417(parameters)
case TwoOfFiveInterleaved:
barcode_content, err = generate2of5Interleaved(parameters)
case TwoOfFive:
barcode_content, err = generate2of5(parameters)
default:
fmt.Println("Unsupported barcode type: ", parameters.Format)
}

28
generation/pdf417.go Normal file
View File

@@ -0,0 +1,28 @@
package generation
import (
"fmt"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/pdf417"
)
func generatePDF417(parameters Parameters) (barcode.Barcode, error) {
var level uint8
switch parameters.ECCLevel {
case 1:
level = byte(1)
case 2:
level = byte(3)
case 3:
level = byte(5)
case 4:
level = byte(8)
}
pdf417Code, err := pdf417.Encode(parameters.Content, level)
if err != nil {
fmt.Println("Error creating Barcode", err)
}
return pdf417Code, err
}

View File

@@ -3,12 +3,15 @@ package generation
type BarcodeType string
const (
Aztec BarcodeType = "aztec"
Codabar BarcodeType = "codabar"
Code93 BarcodeType = "code93"
Code128 BarcodeType = "code128"
QR BarcodeType = "qr"
Datamatrix BarcodeType = "datamatrix"
Aztec BarcodeType = "aztec"
Codabar BarcodeType = "codabar"
Code93 BarcodeType = "code93"
Code128 BarcodeType = "code128"
QR BarcodeType = "qr"
Datamatrix BarcodeType = "datamatrix"
PDF417 BarcodeType = "pdf417"
TwoOfFive BarcodeType = "2of5"
TwoOfFiveInterleaved BarcodeType = "2of5interleaved"
)
type ECCLevel int