package qrcode

import "github.com/edragoev1/pdfjet/v9/src/qrcode"

Package qrcode creates QR code barcodes.

Index

Functions

func Fits

func Fits(str string, errorCorrectionLevel errorcorrectionlevel.ErrorCorrectionLevel) bool

Fits tells whether the string fits in a QR code at the error correction level, so that a program can refuse a text before it draws, and say why, where NewQRCode would panic and EncodeQRCode return an error. The limit is in UTF-8 bytes, not characters: at level M, 2,331 bytes of ASCII, or 2,330 with the ECI of a string that is not all ASCII, so 776 euro signs, 3 bytes each, fit, and 777 do not. A level that is not one fits nothing.

Types

type QRCode

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

QRCode used to create 2D QR Code barcodes. Leave a quiet zone, blank, of 4 modules all around the code, as a scanner needs it. Please see Example_37.

func EncodeQRCode
func EncodeQRCode(str string, errorCorrectionLevel errorcorrectionlevel.ErrorCorrectionLevel) (*QRCode, error)

EncodeQRCode creates the QR code of the string as NewQRCode does, and returns the error, rather than panic, of a string that does not fit in a version 40 symbol at the level, or of a level that is not one, as the constructors of Java, C# and Swift throw it. NewQRCode, which returns no error, panics with it.

func NewQRCode
func NewQRCode(str string, errorCorrectionLevel errorcorrectionlevel.ErrorCorrectionLevel) *QRCode

NewQRCode is used to create 2D QR Code barcodes. The string is encoded in UTF-8, and the symbol is the smallest that holds it, from version 4, 33 by 33 modules, to version 40, 177 by 177 modules. At version 40 it holds up to 2,953 bytes at level L, 2,331 at M, 1,663 at Q and 1,273 at H, a byte fewer when the string is not all ASCII: it then starts with the ECI that tells the reader the bytes are UTF-8. It panics if the string does not fit in a version 40 symbol; EncodeQRCode returns the error instead. @param str the string to encode. @param errorCorrectionLevel the desired error correction level.

func (*QRCode) DrawOn
func (qrcode *QRCode) DrawOn(page *pdfjet.Page) [2]float32

DrawOn draws this barcode on the specified page. The dark modules next to each other in a row are filled as one rectangle, and the pen and the brush of the page are as they were after it. @param page the specified page. @return x and y coordinates of the bottom right corner of this component.

func (*QRCode) GetModules
func (qrcode *QRCode) GetModules() [][]*bool

GetModules returns the modules of the QR code: true for dark and false for light modules.

func (*QRCode) SetAltDescription
func (qrcode *QRCode) SetAltDescription(altDescription string) *QRCode

SetAltDescription sets what the QR code says, such as the web address it carries, for a screen reader: a tagged document, PDF/UA or a PDF/A of level A, then has the QR code as a figure of that description. Without one, it is decoration, which a screen reader skips.

func (*QRCode) SetLocation
func (qrcode *QRCode) SetLocation(x, y float32) pdfjet.Drawable

SetLocation sets the location where this barcode will be drawn on the page. @param x the x coordinate of the top left corner of the barcode. @param y the y coordinate of the top left corner of the barcode.

func (*QRCode) SetModuleColor
func (qrcode *QRCode) SetModuleColor(color int32) *QRCode

SetModuleColor sets the color of the QR code. It is black unless set. color.Transparent leaves it unchanged. Use a dark color on a light background, as navy, dark green or dark brown: most scanners read with red light, in which red, orange and yellow modules look white.

func (*QRCode) SetModuleLength
func (qrcode *QRCode) SetModuleLength(moduleLength float32) *QRCode

SetModuleLength sets the module length of this barcode. The default value is 2.0f @param moduleLength the specified module length.