From 4b43e5554e8c7b89e56d9e87b1b8977d1b89168c Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Sun, 15 May 2016 16:58:49 +0200 Subject: Add support for Pdf417 barcodes --- contrib/barcode/barcode.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'contrib') diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go index 4a143da..c5e4193 100644 --- a/contrib/barcode/barcode.go +++ b/contrib/barcode/barcode.go @@ -32,6 +32,7 @@ import ( "github.com/boombuler/barcode/ean" "github.com/boombuler/barcode/qr" "github.com/boombuler/barcode/twooffive" + "github.com/ruudk/golang-pdf417" "github.com/jung-kurt/gofpdf" ) @@ -131,6 +132,15 @@ func RegisterDataMatrix(pdf barcodePdf, code string) string { return registerBarcode(pdf, bcode, err) } +// RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not +// to the page. Use Barcode() with the return value to put the barcode on the +// page. +func RegisterPdf417(pdf barcodePdf, code string) string { + bcode := pdf417.Encode(code) + + return registerBarcode(pdf, bcode, nil) +} + // RegisterEAN registers a barcode of type EAN to the PDF, but not to the page. // It will automatically detect if the barcode is EAN8 or EAN13. Use Barcode() // with the return value to put the barcode on the page. -- cgit v1.2.1-24-ge1ad From 8dd14effba59e4816750d0009e644da1e44b073a Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 16 May 2016 11:27:38 +0200 Subject: Pass columns and security level to Encode method --- contrib/barcode/barcode.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib') diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go index c5e4193..faed915 100644 --- a/contrib/barcode/barcode.go +++ b/contrib/barcode/barcode.go @@ -135,8 +135,8 @@ func RegisterDataMatrix(pdf barcodePdf, code string) string { // RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not // to the page. Use Barcode() with the return value to put the barcode on the // page. -func RegisterPdf417(pdf barcodePdf, code string) string { - bcode := pdf417.Encode(code) +func RegisterPdf417(pdf barcodePdf, code string, columns int, securityLevel int) string { + bcode := pdf417.Encode(code, columns, securityLevel) return registerBarcode(pdf, bcode, nil) } -- cgit v1.2.1-24-ge1ad From ff13dc5b70f7db15ecfba5d9108b3324f5f41cd0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 16 May 2016 15:08:59 -0400 Subject: Enhance documentation and add test for PDF417 barcode --- contrib/barcode/barcode.go | 13 ++++++++----- contrib/barcode/barcode_test.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'contrib') diff --git a/contrib/barcode/barcode.go b/contrib/barcode/barcode.go index faed915..b2ba2c2 100644 --- a/contrib/barcode/barcode.go +++ b/contrib/barcode/barcode.go @@ -32,8 +32,8 @@ import ( "github.com/boombuler/barcode/ean" "github.com/boombuler/barcode/qr" "github.com/boombuler/barcode/twooffive" - "github.com/ruudk/golang-pdf417" "github.com/jung-kurt/gofpdf" + "github.com/ruudk/golang-pdf417" ) // barcodes represents the barcodes that have been registered through this @@ -132,12 +132,15 @@ func RegisterDataMatrix(pdf barcodePdf, code string) string { return registerBarcode(pdf, bcode, err) } -// RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not -// to the page. Use Barcode() with the return value to put the barcode on the -// page. +// RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not to the +// page. code is the string to be encoded. columns specifies the number of +// barcode columns; this should be a value between 1 and 30 inclusive. +// securityLevel specifies an error correction level between zero and 8 +// inclusive. Barcodes for use with FedEx must set columns to 10 and +// securityLevel to 5. Use Barcode() with the return value to put the barcode +// on the page. func RegisterPdf417(pdf barcodePdf, code string, columns int, securityLevel int) string { bcode := pdf417.Encode(code, columns, securityLevel) - return registerBarcode(pdf, bcode, nil) } diff --git a/contrib/barcode/barcode_test.go b/contrib/barcode/barcode_test.go index c12ff12..f2c57f1 100644 --- a/contrib/barcode/barcode_test.go +++ b/contrib/barcode/barcode_test.go @@ -124,3 +124,16 @@ func ExampleRegisterTwoOfFive() { // Output: // Successfully generated ../../pdf/contrib_barcode_RegisterTwoOfFive.pdf } + +func ExampleRegisterPdf417() { + pdf := createPdf() + + key := barcode.RegisterPdf417(pdf, "1234567895", 10, 5) + barcode.Barcode(pdf, key, 15, 15, 100, 20, false) + + fileStr := example.Filename("contrib_barcode_RegisterPdf417") + err := pdf.OutputFileAndClose(fileStr) + example.Summary(err, fileStr) + // Output: + // Successfully generated ../../pdf/contrib_barcode_RegisterPdf417.pdf +} -- cgit v1.2.1-24-ge1ad