barcode

package
v1.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 17 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Barcode

func Barcode(pdf barcodePdf, code string, x, y, w, h float64, flow bool)

Barcode puts a registered barcode in the current page.

The size should be specified in the units used to create the PDF document. If width or height are left unspecfied, the barcode is not scaled in the unspecified dimensions.

Positioning with x, y and flow is inherited from Fpdf.Image().

func BarcodeUnscalable added in v1.16.3

func BarcodeUnscalable(pdf barcodePdf, code string, x, y float64, w, h *float64, flow bool)

BarcodeUnscalable puts a registered barcode in the current page.

Its arguments work in the same way as that of Barcode(). However, it allows for an unscaled barcode in the width and/or height dimensions. This can be useful if you want to prevent side effects of upscaling.

func GetUnscaledBarcodeDimensions added in v1.16.3

func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64)

GetUnscaledBarcodeDimensions returns the width and height of the unscaled barcode associated with the given code.

func Register

func Register(bcode barcode.Barcode) string

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)
		var width float64 = 100
		var height float64 = 10.0
		barcode.BarcodeUnscalable(pdf, key, 15, 15, &width, &height, false)
	}

	err = pdf.OutputFileAndClose(fileStr)
	example.Summary(err, fileStr)
}
Output:

Successfully generated ../../pdf/contrib_barcode_Register.pdf

func RegisterAztec

func RegisterAztec(pdf barcodePdf, code string, minECCPercent int, userSpecifiedLayers int) string

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.

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.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 RegisterCodabar

func RegisterCodabar(pdf barcodePdf, code string) string

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")
	var width float64 = 100
	var height float64 = 10
	barcode.BarcodeUnscalable(pdf, key, 15, 15, &width, &height, 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

func RegisterCode128(pdf barcodePdf, code string) string

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

func RegisterCode39(pdf barcodePdf, code string, includeChecksum, fullASCIIMode bool) string

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

func RegisterDataMatrix(pdf barcodePdf, code string) string

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

func RegisterEAN(pdf barcodePdf, code string) string

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 RegisterPdf417

func RegisterPdf417(pdf barcodePdf, code string, columns int, securityLevel int) string

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.

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.RegisterPdf417(pdf, "1234567895", 10, 5)
	barcode.Barcode(pdf, key, 15, 15, 100, 10, false)

	fileStr := example.Filename("contrib_barcode_RegisterPdf417")
	err := pdf.OutputFileAndClose(fileStr)
	example.Summary(err, fileStr)
}
Output:

Successfully generated ../../pdf/contrib_barcode_RegisterPdf417.pdf

func RegisterQR

func RegisterQR(pdf barcodePdf, code string, ecl qr.ErrorCorrectionLevel, mode qr.Encoding) string

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, 100, 10, 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

func RegisterTwoOfFive(pdf barcodePdf, code string, interleaved bool) string

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, 10, 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL