Add 2of5 and pdf417
This commit is contained in:
16
generation/2of5.go
Normal file
16
generation/2of5.go
Normal 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
|
||||
}
|
||||
16
generation/2of5interleaved.go
Normal file
16
generation/2of5interleaved.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
28
generation/pdf417.go
Normal 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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user