Is there a way to eliminate text from a barcode image using JavaScript or TypeScript?

This is my unique html code


<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 custom css

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

Here's a javascript function I created for barcode generation:

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

However, I am looking to hide or remove some text beneath the barcode like shown in this example enter image description here

Answer №1

It is recommended to utilize a different type of barcode font, excluding any text.

To start, add the appropriate webfont:

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Libre+Barcode+128">

Next, adjust the CSS accordingly:

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

Answer №2

Looking for an alternative?

Try adjusting the HTML to include an 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>

Adjust the CSS like 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 change will conceal any letters that fall below the barcode.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The functionality of JQuery stops functioning once ajax (Node.js, PUG) is integrated

I've been attempting to incorporate a like feature on my blog post website. When I click on the likes count, it's supposed to trigger an ajax call. In my server.js file, there's a function that handles the POST request to update the number ...

What causes certain elements to update selectively in Ionic view, and why does this phenomenon occur only on specific devices?

My Ionic3 web application includes an HTML page structured like this: <h1> {{question}} </h1> <ion-list formControlName="content" radio-group [(ngModel)]="value"> <li *ngFor="let answer of question.answers"> <i ...

One of the parameters is converging faster than the other with Gradient Descent

My introduction to univariate linear regression using gradient descent was a hands-on experience in JavaScript. const LEARNING_RATE = 0.000001; let m = 0; let b = 0; const hypothesis = x => m * x + b; const learn = (alpha) => { if (x.length < ...

Having trouble with create-react-app? Seeking assistance from the community! Your help would be greatly

Recently attempted to build my first React app, but it seems like React is not in the mood to greet me. After installing Node.js and create-react-app, double-checking their versions to ensure proper installation, I proceeded to create the React app using t ...

The React axios request triggers the UseEffect cleanup function to terminate all subscriptions and asynchronous tasks

I'm currently retrieving data from my API using axios, but the requests are not inside a useEffect function. In fact, I haven't used useEffect at all. Here's a snippet of my code: JSX: <form onSubmit={onSubmitLogin}> <div c ...

Axios error in Express middleware - unable to send headers once they have been processed

I can't seem to figure out why my code is not running correctly. While using Axios in my middleware, I am encountering this error message: Error: Can't set headers after they are sent. This is the snippet of my code (utilizing Lodash forEach): ...

Error Encountered: Unable to locate angular/core module in Angular 2

I have encountered an issue while setting up a new Angular2 app from the quickstart folder on the Angular website. Despite following all suggested solutions, I am still facing errors. After running npm install, everything seems fine as I can see my node_mo ...

Leveraging NextJS to perform server side rendering by injecting parameters from a caller component

I'm currently in the process of creating an application with a storefront using nextJS. I've successfully utilized getServerSideProps when loading a new page. This particular page is quite complex, as it consists of multiple components, each req ...

I am curious about why I am unable to utilize inline functions in component props. Could you please provide a detailed explanation and perhaps give an example to illustrate? Furthermore, what is

Please take note: The component prop accepts a component, not a render function. Do not pass an inline function (e.g. component={() => }), as this will cause your component to unmount and remount, losing all state when the parent component re-renders. F ...

Bing Translator and XMLHttpRequest are two powerful tools for translating and

When running the code snippet below, I encounter an issue where I am not receiving status 200 and responseText. However, when using the following URL: http://api.microsofttranslator.com/V2/Http.svc/GetLanguagesForTranslate?appId=F1B50AB0743B541AA8C070890 ...

Utilizing JavaScript to Parse RSS XML Feeds Across Domains

Looking to parse an RSS (XML) file without relying on the Google RSS feed. I have attempted using JSONP, but it resulted in downloading the file and throwing an error "Uncaught SyntaxError: Unexpected token < ". $.ajax({ type: "GET", ur ...

Having trouble with the npm Twitter API functionality?

I'm attempting to execute a simple stream using an example code snippet. Here is the code I am working with: var twit = require('twitter'); var twitter = new twit({ consumer_key: '[KEY]', consumer_secret: &ap ...

How can I pass an Objective-C object to JavaScript?

Currently, I am working on a UIWebView project that involves HTML and JavaScript. One of my friends is working on something similar but for Android. The challenge I'm facing is that in Android, there is a simple way to send an Android object to JavaS ...

Utilize rest parameters for destructuring操作

I am attempting to destructure a React context using rest parameters within a custom hook. Let's say I have an array of enums and I only want to return the ones passed into the hook. Here is my interface for the context type enum ConfigItem { Some ...

Issue with parsing JSON data in AgGrid

I'm currently utilizing Ag-grid within my Angular project. The rowData is populated with data from a JSON file stored in the assets folder, which is fetched using HttpClient. However, I'm encountering an issue where the data fails to load and an ...

Utilize the function with another function (difficult to articulate)

Apologies in advance for my beginner question. Review the code snippet below: var dt = new Date(t*1000); var m = "0" + dt.getMinutes(); Depending on the t variable (unix time), the output can be one of the following: m = 054 // 54 minutes m = 03 // 3 min ...

function complete, ajax request finished

When working with Ajax to get data, I encountered a situation where I needed to return the value of `username` from within an if statement that is inside a loop and a function. How can I achieve this? Your help would be appreciated. $.ajax({ ...

Learn how to access an array within an object using JavaScript and an API URL

Trying to fetch data from the swapi API to display film titles using jQuery. Below is the JavaScript code: $(function(){ function promiseTest(){ return $.ajax({ type: 'GET', url: 'https://swapi.co/api/people/', } ...

I am having trouble getting my AngularJS client to properly consume the RESTful call

As I venture into the world of AngularJS and attempt to work with a RESTful service, I am encountering a challenge. Upon making a REST call to http://localhost:8080/application/webapi/myApp/, I receive the following JSON response: { "content": "Hel ...

Typescript HashMap implementation with Lists as values

Currently delving into TypeScript, I am attempting to generate a collection in a manner akin to the following Java example: HashMap<String, List<String>> hashMap = new HashMap<String,List<String>>(); Struggling to locate any releva ...