barcode

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package barcode generates 1D and 2D barcodes that can be rendered directly into a PDF content stream as vector graphics (no images).

Package barcode generates 1D and 2D barcodes and renders them directly into PDF content streams as vector graphics.

Supported formats:

Each constructor returns a Barcode holding a 2D module grid. Call Barcode.Draw to render the barcode onto a content.Stream at any position and size. All output is vector (filled rectangles), so barcodes remain sharp at any zoom level.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Barcode

type Barcode struct {
	// contains filtered or unexported fields
}

Barcode is a generated barcode ready to be drawn into a PDF.

func NewCode128 added in v0.6.0

func NewCode128(data string) (*Barcode, error)

NewCode128 generates a Code 128 barcode from a string. It encodes the full ASCII range (0-127) by selecting code sets A, B, and C automatically, using Code C for runs of digits. Bytes above 127 return an error.

func NewEAN13 added in v0.6.0

func NewEAN13(data string) (*Barcode, error)

EAN13 generates an EAN-13 barcode from a 13-digit string. If 12 digits are provided, the check digit is computed automatically. Returns an error if the input is not 12 or 13 digits.

func NewQR added in v0.6.0

func NewQR(data string) (*Barcode, error)

QR generates a QR Code barcode from a string. Uses the most efficient encoding mode with error correction level M (15% recovery). Automatically selects the smallest version (1-40) that fits the data.

func NewQRWithECC added in v0.6.0

func NewQRWithECC(data string, level ECCLevel) (*Barcode, error)

NewQRWithECC generates a QR Code barcode with the specified error correction level. Automatically selects the most efficient encoding mode and smallest version (1-40).

func (*Barcode) Draw

func (b *Barcode) Draw(stream *content.Stream, x, y, w, h float64)

Draw renders the barcode into a PDF content stream as filled rectangles. x, y is the bottom-left corner; w, h are the total dimensions in points.

func (*Barcode) Height

func (b *Barcode) Height() int

Height returns the number of modules tall.

func (*Barcode) Width

func (b *Barcode) Width() int

Width returns the number of modules wide.

type ECCLevel

type ECCLevel int

ECCLevel represents the error correction level for QR codes.

const (
	ECCLevelL ECCLevel = iota // 7% recovery
	ECCLevelM                 // 15% recovery
	ECCLevelQ                 // 25% recovery
	ECCLevelH                 // 30% recovery
)

Jump to

Keyboard shortcuts

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