summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuud Kamphuis <ruudk@mphuis.com>2016-12-27 13:46:03 +0100
committerKurt Jung <kurt.w.jung@gmail.com>2016-12-27 07:46:03 -0500
commita1764391c7954b6bf5f49d09d4a5a32924e74dc9 (patch)
tree6763e6a9167de39e3346a5413c360fdacef0f684
parent81e1e93b509dd8fc2775e37e5a6e1f416285a66f (diff)
Add support for Aztec barcodes (#101)
* Add RegisterAztec * Add test for RegisterAztec
-rw-r--r--contrib/barcode/barcode.go10
-rw-r--r--contrib/barcode/barcode_test.go13
2 files changed, 23 insertions, 0 deletions
diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go
index 0649564..63a4908 100644
--- a/contrib/barcode/barcode.go
+++ b/contrib/barcode/barcode.go
@@ -21,6 +21,7 @@ import (
"bytes"
"errors"
"github.com/boombuler/barcode"
+ "github.com/boombuler/barcode/aztec"
"github.com/boombuler/barcode/codabar"
"github.com/boombuler/barcode/code128"
"github.com/boombuler/barcode/code39"
@@ -110,6 +111,15 @@ func Register(bcode barcode.Barcode) string {
return key
}
+// RegisterAztec registers a barcode of type Aztec to the PDF, but not to
+// the page. Use Barcode() with the return value to put the barcode on the page.
+// code is the string to be encoded. minECCPercent is the error correction percentage. 33 is the default.
+// userSpecifiedLayers can be a value between -4 and 32 inclusive.
+func RegisterAztec(pdf barcodePdf, code string, minECCPercent int, userSpecifiedLayers int) string {
+ bcode, err := aztec.Encode([]byte(code), minECCPercent, userSpecifiedLayers)
+ return registerBarcode(pdf, bcode, err)
+}
+
// RegisterCodabar registers a barcode of type Codabar to the PDF, but not to
// the page. Use Barcode() with the return value to put the barcode on the page.
func RegisterCodabar(pdf barcodePdf, code string) string {
diff --git a/contrib/barcode/barcode_test.go b/contrib/barcode/barcode_test.go
index f2c57f1..c3c648c 100644
--- a/contrib/barcode/barcode_test.go
+++ b/contrib/barcode/barcode_test.go
@@ -47,6 +47,19 @@ func ExampleRegisterCodabar() {
// Successfully generated ../../pdf/contrib_barcode_RegisterCodabar.pdf
}
+func ExampleRegisterAztec() {
+ pdf := createPdf()
+
+ key := barcode.RegisterAztec(pdf, "aztec", 33, 0)
+ barcode.Barcode(pdf, key, 15, 15, 100, 100, false)
+
+ fileStr := example.Filename("contrib_barcode_RegisterAztec")
+ err := pdf.OutputFileAndClose(fileStr)
+ example.Summary(err, fileStr)
+ // Output:
+ // Successfully generated ../../pdf/contrib_barcode_RegisterAztec.pdf
+}
+
func ExampleRegisterCode128() {
pdf := createPdf()