import { useEffect, useRef } from 'react'; import JsBarcode from 'jsbarcode'; /** * Code 128 barcode of `value`, drawn on a canvas (black bars on white, no caption). Drawn synchronously in the effect so the * PDF capture never sees an empty canvas. Legacy printed the permit number as a barcode image * (application.objCMN.generatebarCode); this is the same idea. */ export function Barcode({ value, height = 64, barWidth = 2 }: { value: string; height?: number; barWidth?: number }) { const ref = useRef(null); useEffect(() => { if (!value || !ref.current) return; try { JsBarcode(ref.current, value, { format: 'CODE128', displayValue: false, width: barWidth, height, margin: 0, background: '#ffffff', lineColor: '#000000' }); } catch { /* an unprintable value simply leaves the canvas empty */ } }, [value, height, barWidth]); return ; }