leumas-private-shared
Version:
Private React JSX Package For Leumas Shared Components, Headers, Footers, Asides, Login Pages, API Key Manager and much more. Styles and everything reusable to avoid DRY code across all of our subdomains
23 lines (20 loc) • 750 B
JSX
// generateBarcode.jsx
import bwipjs from 'bwip-js';
export const generateBarcode = (canvasRef, barcodeValue) => {
if (!canvasRef.current) {
console.error('Canvas reference is not valid');
return;
}
try {
bwipjs.toCanvas(canvasRef.current, {
bcid: 'code128', // Barcode type
text: barcodeValue, // Text to encode
scale: 3, // 3x scaling factor
height: 10, // Bar height, in millimeters
includetext: true, // Show human-readable text
textxalign: 'center', // Always good to set this
});
} catch (err) {
console.error('Error generating barcode:', err);
}
};