Barcode Generator Implementation for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1215
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1043
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Barcode Generator Implementation

Barcodes are needed in inventory systems (label generation), e-commerce (price tag printing), asset tracking systems, and document workflows. The browser generates the barcode client-side without API requests — the user immediately sees the result and can print it.

Barcode Formats

Format Application Data Length
Code 128 Warehouse inventory, logistics Any length
EAN-13 Trade, food products 13 digits
EAN-8 Small packages 8 digits
Code 39 Manufacturing, medicine Letters + digits
UPC-A North America, retail 12 digits
ITF-14 Box packaging, SSCC 14 digits
QR Code "Honest Mark" labeling Any data

JsBarcode Library

JsBarcode supports all popular formats, works with <canvas>, <svg>, and <img>.

npm install jsbarcode
npm install -D @types/jsbarcode

Component

import JsBarcode from 'jsbarcode'
import { useEffect, useRef } from 'react'

interface BarcodeProps {
  value: string
  format?: string
  width?: number
  height?: number
  displayValue?: boolean
  lineColor?: string
  background?: string
  fontSize?: number
  margin?: number
}

export function Barcode({
  value,
  format = 'CODE128',
  width = 2,
  height = 80,
  displayValue = true,
  lineColor = '#000000',
  background = '#ffffff',
  fontSize = 14,
  margin = 10,
}: BarcodeProps) {
  const svgRef = useRef<SVGSVGElement>(null)

  useEffect(() => {
    if (!svgRef.current || !value) return

    try {
      JsBarcode(svgRef.current, value, {
        format,
        width,
        height,
        displayValue,
        lineColor,
        background,
        fontSize,
        margin,
        textMargin: 4,
        fontOptions: 'bold',
        font: 'monospace',
      })
    } catch (e) {
      // Invalid value for format (e.g., letters in EAN-13)
      console.warn(`Invalid barcode value "${value}" for format ${format}:`, e)
    }
  }, [value, format, width, height, displayValue, lineColor, background, fontSize, margin])

  return <svg ref={svgRef} />
}

Batch label generation

For printing multiple barcodes on one page:

function LabelSheet({ items }: { items: { sku: string; name: string; price: number }[] }) {
  const printRef = useRef<HTMLDivElement>(null)

  function handlePrint() {
    const content = printRef.current!
    const win = window.open('', '_blank')!
    win.document.write(`
      <html>
        <head>
          <title>Labels</title>
          <style>
            body { margin: 0; }
            .sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; padding: 10mm; }
            .label { border: 0.5pt solid #ccc; padding: 3mm; text-align: center; page-break-inside: avoid; }
            .label-name { font-size: 9pt; margin-bottom: 2mm; overflow: hidden; white-space: nowrap; }
            .label-price { font-size: 14pt; font-weight: bold; margin-top: 2mm; }
            @media print { @page { size: A4; margin: 0; } }
          </style>
        </head>
        <body>
          <div class="sheet">${content.innerHTML}</div>
        </body>
      </html>
    `)
    win.document.close()
    win.focus()
    win.print()
    win.close()
  }

  return (
    <div>
      <button onClick={handlePrint} className="mb-4 px-4 py-2 bg-blue-600 text-white rounded">
        Print labels
      </button>
      <div ref={printRef} className="grid grid-cols-3 gap-1">
        {items.map((item) => (
          <div key={item.sku} className="border p-2 text-center text-xs">
            <div className="truncate text-xs">{item.name}</div>
            <Barcode value={item.sku} format="CODE128" height={50} fontSize={10} margin={4} />
            <div className="font-bold">{item.price.toLocaleString()} ₽</div>
          </div>
        ))}
      </div>
    </div>
  )
}

Server-side generation (Node.js)

npm install jsbarcode canvas
import { createCanvas } from 'canvas'
import JsBarcode from 'jsbarcode'

export function generateBarcodeBuffer(value: string, format = 'CODE128'): Buffer {
  const canvas = createCanvas(400, 150)
  JsBarcode(canvas, value, {
    format,
    width: 2,
    height: 80,
    displayValue: true,
    fontSize: 14,
    margin: 10,
  })
  return canvas.toBuffer('image/png')
}

// In API route:
const buffer = generateBarcodeBuffer(req.query.sku)
res.setHeader('Content-Type', 'image/png')
res.send(buffer)

EAN-13 with check digit

function calculateEAN13Checksum(digits: string): string {
  if (digits.length !== 12) throw new Error('EAN-13 requires exactly 12 digits')

  let sum = 0
  for (let i = 0; i < 12; i++) {
    sum += parseInt(digits[i]) * (i % 2 === 0 ? 1 : 3)
  }

  const checkDigit = (10 - (sum % 10)) % 10
  return digits + checkDigit
}

// Generate barcode with check digit
const ean13 = calculateEAN13Checksum('460000000001')
// '4600000000015'

What we do

Connect JsBarcode, implement component with needed format, configure label printing (CSS Print, proper A4 spacing). For server-side generation — API endpoint returning PNG/SVG by SKU.

Timeline: 0.5–1 day.