barcode

package
v2.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Funciones para generar códigos de barras 1D en formato SVG.

Se han seguido las mismas reglas de generación que usan las impresoras ESC/POS en el comando GS k, consultar https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/gs_lk.html

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBarcodeBARS

func GetBarcodeBARS(code string, kind KIND) (bars, hri string, err error)

Genera la secuencia de módulos de las barras de código:

  • code: código a representar
  • kind: tipo de código de barras
Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/barcode"
)

func main() {
	bars, hri, _ := barcode.GetBarcodeBARS("123456", barcode.C128X)
	fmt.Printf("%s: %s\n", hri, bars)
}
Output:

123456: 2112321122321311233311211321312331112

func GetBarcodeSVG

func GetBarcodeSVG(code string, kind KIND, w, h float64, color string, hri HRI, inline bool) (string, error)

Genera un documento SVG:

  • code: código a representar
  • kind: tipo de código de barras
  • w: ancho del módulo
  • h: altura del código, incluye texto HRI
  • hri: posición del texto HRI
  • inline: suprime cabeceras SVG para embeber en HTML
Example
package main

import (
	"fmt"

	"github.com/horus-es/go-util/v2/barcode"
)

func main() {
	svg, _ := barcode.GetBarcodeSVG("123456", barcode.C128X, 2, 100, "#000", barcode.Below, false)
	fmt.Print(svg)

}
Output:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="156.00000" height="116.00000" version="1.1" xmlns="http://www.w3.org/2000/svg">
	<g fill="#000" stroke="none">
		<rect x="10.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="16.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="22.00000" y="0.00000" width="6.00000" height="100.00000" />
		<rect x="32.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="36.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="44.00000" y="0.00000" width="6.00000" height="100.00000" />
		<rect x="54.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="62.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="66.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="76.00000" y="0.00000" width="6.00000" height="100.00000" />
		<rect x="88.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="92.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="98.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="106.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="112.00000" y="0.00000" width="6.00000" height="100.00000" />
		<rect x="120.00000" y="0.00000" width="4.00000" height="100.00000" />
		<rect x="130.00000" y="0.00000" width="6.00000" height="100.00000" />
		<rect x="138.00000" y="0.00000" width="2.00000" height="100.00000" />
		<rect x="142.00000" y="0.00000" width="4.00000" height="100.00000" />
	<text x="78.00000" text-anchor="middle" dominant-baseline="hanging" y="102.00000" fill="#000" font-size="15px">123456</text>
	</g>
</svg>

Types

type HRI

type HRI int
const (
	None  HRI = 0
	Above HRI = 1
	Below HRI = 2
	Both  HRI = 3
)

type KIND

type KIND int
const (
	C39     KIND = 1  // Code39
	C93     KIND = 2  // Code93
	I25     KIND = 3  // Interleaved 2/5
	C128    KIND = 4  // Code128 con secuencias esc/pos
	C128X   KIND = 5  // Code128 automático
	EAN13   KIND = 6  // EAN-13
	EAN8    KIND = 7  // EAN-8
	UPCA    KIND = 8  // UPC-A
	UPCE    KIND = 9  // UPC-E
	CODABAR KIND = 10 // CODABAR
)

Jump to

Keyboard shortcuts

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