Documentation ¶
Overview ¶
Package barcode provides helper methods for adding barcodes of different types to your pdf document. It relies on the github.com/boombuler/barcode package for the barcode creation.
Index ¶
- func Barcode(pdf barcodePdf, code string, x, y, w, h float64, flow bool)
- func Register(bcode barcode.Barcode) string
- func RegisterCodabar(pdf barcodePdf, code string) string
- func RegisterCode128(pdf barcodePdf, code string) string
- func RegisterCode39(pdf barcodePdf, code string, includeChecksum, fullASCIIMode bool) string
- func RegisterDataMatrix(pdf barcodePdf, code string) string
- func RegisterEAN(pdf barcodePdf, code string) string
- func RegisterQR(pdf barcodePdf, code string, ecl qr.ErrorCorrectionLevel, mode qr.Encoding) string
- func RegisterTwoOfFive(pdf barcodePdf, code string, interleaved bool) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Barcode ¶
Barcode puts a registered barcode in the current page.
The size should be specified in the units used to create the PDF document.
Positioning with x, y and flow is inherited from Fpdf.Image().
func Register ¶
Register registers a barcode but does not put it on the page. Use Barcode() with the same code to put the barcode on the PDF page.
Example ¶
package main import ( "github.com/boombuler/barcode/code128" "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() fileStr := example.Filename("contrib_barcode_Register") bcode, err := code128.Encode("gofpdf") if err == nil { key := barcode.Register(bcode) barcode.Barcode(pdf, key, 15, 15, 100, 10, false) } err = pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_Register.pdf
func RegisterCodabar ¶
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.
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterCode128(pdf, "codabar") barcode.Barcode(pdf, key, 15, 15, 100, 10, false) fileStr := example.Filename("contrib_barcode_RegisterCodabar") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterCodabar.pdf
func RegisterCode128 ¶
RegisterCode128 registers a barcode of type Code128 to the PDF, but not to the page. Use Barcode() with the return value to put the barcode on the page.
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterCode128(pdf, "code128") barcode.Barcode(pdf, key, 15, 15, 100, 10, false) fileStr := example.Filename("contrib_barcode_RegisterCode128") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterCode128.pdf
func RegisterCode39 ¶
RegisterCode39 registers a barcode of type Code39 to the PDF, but not to the page. Use Barcode() with the return value to put the barcode on the page.
includeChecksum and fullASCIIMode are inherited from code39.Encode().
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterCode39(pdf, "CODE39", false, true) barcode.Barcode(pdf, key, 15, 15, 100, 10, false) fileStr := example.Filename("contrib_barcode_RegisterCode39") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterCode39.pdf
func RegisterDataMatrix ¶
RegisterDataMatrix registers a barcode of type DataMatrix to the PDF, but not to the page. Use Barcode() with the return value to put the barcode on the page.
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterDataMatrix(pdf, "datamatrix") barcode.Barcode(pdf, key, 15, 15, 20, 20, false) fileStr := example.Filename("contrib_barcode_RegisterDataMatrix") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterDataMatrix.pdf
func RegisterEAN ¶
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.
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterEAN(pdf, "96385074") barcode.Barcode(pdf, key, 15, 15, 100, 10, false) fileStr := example.Filename("contrib_barcode_RegisterEAN") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterEAN.pdf
func RegisterQR ¶
RegisterQR registers a barcode of type QR to the PDF, but not to the page. Use Barcode() with the return value to put the barcode on the page.
The ErrorCorrectionLevel and Encoding mode are inherited from qr.Encode().
Example ¶
package main import ( "github.com/boombuler/barcode/qr" "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterQR(pdf, "qrcode", qr.H, qr.Unicode) barcode.Barcode(pdf, key, 15, 15, 20, 20, false) fileStr := example.Filename("contrib_barcode_RegisterQR") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterQR.pdf
func RegisterTwoOfFive ¶
RegisterTwoOfFive registers a barcode of type TwoOfFive to the PDF, but not to the page. Use Barcode() with the return value to put the barcode on the page.
The interleaved bool is inherited from twooffive.Encode().
Example ¶
package main import ( "github.com/jung-kurt/gofpdf" "github.com/jung-kurt/gofpdf/contrib/barcode" "github.com/jung-kurt/gofpdf/internal/example" ) func createPdf() (pdf *gofpdf.Fpdf) { pdf = gofpdf.New("L", "mm", "A4", "") pdf.SetFont("Helvetica", "", 12) pdf.SetFillColor(200, 200, 220) pdf.AddPage() return } func main() { pdf := createPdf() key := barcode.RegisterTwoOfFive(pdf, "1234567895", true) barcode.Barcode(pdf, key, 15, 15, 100, 20, false) fileStr := example.Filename("contrib_barcode_RegisterTwoOfFive") err := pdf.OutputFileAndClose(fileStr) example.Summary(err, fileStr) }
Output: Successfully generated ../../pdf/contrib_barcode_RegisterTwoOfFive.pdf
Types ¶
This section is empty.