pdf417

package module
v0.0.0-...-a7e3863 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: MIT Imports: 7 Imported by: 101

README

PDF417 barcodes in Golang

CI

This is a port of https://github.com/ihabunek/pdf417-php

This library encodes data to a PixelGrid that can be used to display the barcode. You can use the PixelGrid to draw the barcode on anything. Check pdf417_test.go for an example.

I only needed a way to draw PDF417 barcodes onto a FPDF PDF file. See example: examples/fpdf.go

If you want to export the barcode to an image, you have to create something that puts the PixelGrid onto the image. If you find a way, please submit a PR :)

Documentation

Index

Constants

View Source
const BYTE_SWITCH_CODE_WORD = 901

Code word used to switch to Text mode.

View Source
const BYTE_SWITCH_CODE_WORD_ALT = 924

Alternate code word used to switch to Text mode; used when number of Texts to encode is divisible by 6.

View Source
const DEFAULT_COLUMNS = 6
View Source
const DEFAULT_SECURITY_LEVEL = 2
View Source
const MAX_CODE_WORDS = 925
View Source
const MAX_COLUMNS = 30
View Source
const MAX_ROWS = 90
View Source
const MAX_SECURITY_LEVEL = 8
View Source
const MIN_COLUMNS = 1
View Source
const MIN_ROWS = 3
View Source
const MIN_SECURITY_LEVEL = 0
View Source
const NUMBER_SWITCH_CODE_WORD int = 902
View Source
const PADDING_CODE_WORD = 900
View Source
const PADDING_VALUE = 29

Since each code word consists of 2 characters, a padding value is needed when encoding a single character. 29 is used as padding because it's a switch in all 4 submodes, and doesn't add any data.

View Source
const START_CHARACTER = 0x1fea8
View Source
const STOP_CHARACTER = 0x3fa29
View Source
const SUBMODE_LOWER = "SUBMODE_LOWER"

Lowercase submode.

View Source
const SUBMODE_MIXED = "SUBMODE_MIXED"

mixed submode (numbers and some punctuation).

View Source
const SUBMODE_PUNCT = "SUBMODE_PUNCT"

Punctuation submode.

View Source
const SUBMODE_UPPER = "SUBMODE_UPPER"

Uppercase submode.

View Source
const SWITCH_LOWER = "SWITCH_LOWER"

Switch to lowercase submode.

View Source
const SWITCH_MIXED = "SWITCH_MIXED"

Switch to mixed submode.

View Source
const SWITCH_PUNCT = "SWITCH_PUNCT"

Switch to punctuation submode.

View Source
const SWITCH_PUNCT_SINGLE = "SWITCH_PUNCT_SINGLE"

Switch to punctuation submode for a single character.

View Source
const SWITCH_UPPER = "SWITCH_UPPER"

Switch to uppercase submode.

View Source
const SWITCH_UPPER_SINGLE = "SWITCH_UPPER_SINGLE"

Switch to uppercase submode for a single character.

View Source
const TEXT_SWITCH_CODE_WORD int = 900

Code word used to switch to Text mode.

Variables

This section is empty.

Functions

func ComputeReedSolomon

func ComputeReedSolomon(data []int, level int) []int

Types

type Barcode

type Barcode struct {
	Data          string
	CodeWords     []int
	Columns       int
	Rows          int
	Codes         [][]int
	SecurityLevel int
	// contains filtered or unexported fields
}

func Encode

func Encode(data string, columns int, securityLevel int) *Barcode

func (*Barcode) At

func (c *Barcode) At(x, y int) color.Color

func (*Barcode) Bounds

func (c *Barcode) Bounds() image.Rectangle

func (*Barcode) CheckSum

func (c *Barcode) CheckSum() int

func (*Barcode) ColorModel

func (c *Barcode) ColorModel() color.Model

func (*Barcode) Content

func (c *Barcode) Content() string

func (*Barcode) Metadata

func (c *Barcode) Metadata() barcode.Metadata

func (*Barcode) PixelGrid

func (barcode *Barcode) PixelGrid() [][]bool

type ByteEncoder

type ByteEncoder struct {
}

func CreateByteEncoder

func CreateByteEncoder() *ByteEncoder

func (ByteEncoder) CanEncode

func (ByteEncoder) CanEncode(char string) bool

func (ByteEncoder) GetSwitchCode

func (ByteEncoder) GetSwitchCode(data string) int

type Chain

type Chain struct {
	Data    string
	Encoder Encoder
}

type DataEncoder

type DataEncoder struct {
	Encoders       []Encoder
	DefaultEncoder Encoder
}

func CreateDataEncoder

func CreateDataEncoder() DataEncoder

func (DataEncoder) Encode

func (dataEncoder DataEncoder) Encode(data string) []int

func (DataEncoder) SplitToChains

func (dataEncoder DataEncoder) SplitToChains(data string) []Chain

type Encoder

type Encoder interface {
	GetName() string
	CanEncode(char string) bool
	GetSwitchCode(data string) int
	Encode(data string, addSwitchCode bool) []int
}

type NumberEncoder

type NumberEncoder struct {
}

func CreateNumberEncoder

func CreateNumberEncoder() *NumberEncoder

func (NumberEncoder) CanEncode

func (encoder NumberEncoder) CanEncode(char string) bool

func (NumberEncoder) Encode

func (encoder NumberEncoder) Encode(digits string, addSwitchCode bool) []int

func (NumberEncoder) GetName

func (encoder NumberEncoder) GetName() string

func (NumberEncoder) GetSwitchCode

func (encoder NumberEncoder) GetSwitchCode(data string) int

type TextEncoder

type TextEncoder struct {
	CharacterTables map[string][]string
	Switching       map[string]map[string][]string
	SwitchSubmode   map[string]string
	ReverseLookup   map[string]map[string]int
}

func CreateTextEncoder

func CreateTextEncoder() *TextEncoder

func (TextEncoder) CanEncode

func (encoder TextEncoder) CanEncode(char string) bool

func (TextEncoder) Encode

func (encoder TextEncoder) Encode(data string, addSwitchCode bool) []int

func (TextEncoder) GetName

func (encoder TextEncoder) GetName() string

func (TextEncoder) GetSwitchCode

func (TextEncoder) GetSwitchCode(data string) int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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