javascriptangulartypescriptbarcodebarcode-printing

how can i remove text from barcode image in javascript or typescript?


This is my html


<div class="pr-2" style="width: 130px">
            <div *ngIf="!element.editing" >
              <span class="ss">{{element.barcode}}</span>
              </div>
              <div *ngIf="element.editing" >
                <input type="text" [(ngModel)]="element.barcode" style="width: 130px"/>
                </div>
          </div>

This is my css

.ss {
  font-family: 'Libre Barcode 128 Text', cursive;
  font-size: 22px;
}

This is my javascript function

barcodeGenerator(value){

  let x = value
  let i, j, intWeight, intLength, intWtProd = 0, arrayData = [];
  let arraySubst = [ "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê" ];

/*
 * Checksum Calculation for Code 128 B
 */
  intLength = x.length;
    arrayData[0] = 104; // Assume Code 128B, Will revise to support A, C and switching.
    intWtProd = 104;
    for (j = 0; j < intLength; j += 1) {
            arrayData[j + 1] = x.charCodeAt(j) - 32; // Have to convert to Code 128 encoding
            intWeight = j + 1; // to generate the checksum
            intWtProd += intWeight * arrayData[j + 1]; // Just a weighted sum
    }
    arrayData[j + 1] = intWtProd % 103; // Modulo 103 on weighted sum
    arrayData[j + 2] = 106; // Code 128 Stop character
  const chr = parseInt(arrayData[j + 1], 10); // Gotta convert from character to a number
  if (chr > 94) {
    var chrString = arraySubst[chr - 95];
  } else {
    chrString = String.fromCharCode(chr + 32);
  }

  // document.getElementById(id).innerHTML =
    return 'Ì' + // Start Code B
    x + // The originally typed string
    chrString + // The generated checksum
    'Î'; // Stop Code
  
    // return `<span class="ss">${x}</span>`;
}

This is the Output enter image description here

but i want to hide/remove text under barcode.

like this enter image description here


Solution

  • As an alternative

    Change html to this (extra span):

    <div class="pr-2" style="width: 130px">
            <div *ngIf="!element.editing" >
              <span class="ss"><span>{{element.barcode}}</span></span>
              </div>
              <div *ngIf="element.editing" >
                <input type="text" [(ngModel)]="element.barcode" style="width: 130px"/>
                </div>
          </div>
    

    And css to this:

    .ss span{
      font-family: 'Libre Barcode 128 Text', cursive;
      font-size: 22px;
       display: inline-block;
       transform: scaleY(3);
    }
    
    .ss {height: 22px;
      overflow: hidden;
      display: inline-block;
    

    }

    This will hide the letters that are under the barcode.