VintaSoft Barcode .NET SDK 15.3: Documentation for Web developer
In This Topic
    Recognize barcodes in image in "Angular and ASP.NET Core" application
    In This Topic
    This tutorial shows how to create a blank "Angular and ASP.NET Core" application in Visual Studio .NET 2026 and recognize barcodes in image in "Angular and ASP.NET Core" application.

    Here are steps, which must be done:
    1. Create a blank "Angular and ASP.NET Core" application.

      Open Visual Studio .NET 2026 and create a new project, of "Angular and ASP.NET Core" application type:

      Configure the project to use .NET 10.0:

    2. "AngularApp1.Server" project: Add references to the Vintasoft assemblies.

      Add references to the nuget-packages "Vintasoft.Barcode", "Vintasoft.Barcode.SkiaSharp" and "Vintasoft.Barcode.AspNetCore.ApiControllers" to the "AngularApp1.Server" project.

    3. "AngularApp1.Server" project: Create web service for barcode recognition.

      • Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
      • Select Empty API controller template, set the controller name to the "MyVintasoftBarcodeApiController" and press the "Add" button
      • Specify that MyVintasoftBarcodeApiController class is derived from Vintasoft.Barcode.AspNetCore.ApiControllers.VintasoftBarcodeApiController class

        Here are source codes of MyVintasoftBarcodeApiController class:
        using Vintasoft.Barcode.AspNetCore.ApiControllers;
        
        namespace WebApplication1.Controllers
        {
            public class MyVintasoftBarcodeApiController : VintasoftBarcodeApiController
            {
        
                public MyVintasoftBarcodeApiController(IWebHostEnvironment hostingEnvironment)
                    : base(hostingEnvironment)
                {
                }
        
            }
        }
        
        
    4. "AngularApp1.Server" project: Specify image file that contains barcodes.

      Create folder "wwwroot\UploadedImageFiles\SessionID" in "AngularApp1.Server" project and copy image file with barcodes "<InstallPath>VintaSoft\Barcode .NET 15.3\Images\AllSupportedBarcodes.png" to the created folder. We will recognize barcodes in this image.
    5. "AngularApp1.Server" project: Add reference to the nuget-package "Microsoft.AspNetCore.Mvc.NewtonsoftJson" for deserialization of barcode recognition results.

      • Add reference to the nuget-package "Microsoft.AspNetCore.Mvc.NewtonsoftJson" to the "AngularApp1.Server" project:


      • Open the "Program.cs" file and add code line "builder.Services.AddControllersWithViews().AddNewtonsoftJson();". This is necessary for correct deserialization of barcode recognition results.

        Here are source codes of Program.cs:
        var builder = WebApplication.CreateBuilder(args);
        
        // Add services to the container.
        
        builder.Services.AddControllersWithViews().AddNewtonsoftJson();
        
        var app = builder.Build();
        
        app.UseDefaultFiles();
        app.MapStaticAssets();
        
        // Configure the HTTP request pipeline.
        
        app.UseHttpsRedirection();
        
        app.UseAuthorization();
        
        app.MapControllers();
        
        app.MapFallbackToFile("/index.html");
        
        app.Run();
        
        
    6. "AngularApp1.Server" project: Delete files, which are not necessary.

      Delete files "WeatherForecast.cs" and "Controllers\WeatherForecastController.cs" in "AngularApp1.Server" project - the WeatherForecast Web API controller is not necessary in this demo.
    7. "angularapp1.client" project: Compile the solution for restoring TypeScript-dependencies in "angularapp1.client" project.

    8. "angularapp1.client" project: Add JavaScript files and TypeScript modules to the "angularapp1.client" project.

      • Add the "assets" folder to the "src\app\" folder in "angularapp1.client" project.

      • Copy Vintasoft.Shared.js, Vintasoft.Shared.d.ts, Vintasoft.Barcode.js and Vintasoft.Barcode.d.ts files from "<InstallPath>\VintaSoft Barcode .NET 15.3\Bin\JavaScript\" folder to the "src\app\assets\" folder in "angularapp1.client" project.


      • Add references to Vintasoft JavaScript files to the "projects => angularapp1.client => architect => build => options => scripts" section in "angular.json" file in "angularapp1.client" project:
        ...
        "scripts": [
          "src/app/assets/Vintasoft.Shared.js",
          "src/app/assets/Vintasoft.Barcode.js"
        ]
        ...
        

    9. "angularapp1.client" project: Create Angular component that recognizes barcodes in image.

      • Open "src\app\app.component.html" file in "angularapp1.client" project, clear the file, add HTML markup (page header and image element that will display barcode recognition result) to the "app.component.html" file:
        <h1>Angular Barcode Reader Demo</h1>
        
        <div id="barcodeInformation"></div>
        
        



      • Open "src\app\app.component.ts" file in "angularapp1.client" project, clear the file, add TypeScript code to the "app.component.ts" file:
        import { HttpClient } from '@angular/common/http';
        import { Component, OnInit } from '@angular/core';
        
        @Component({
          selector: 'app-root',
          templateUrl: './app.component.html',
          styleUrls: ['./app.component.css']
        })
        export class AppComponent implements OnInit {
          constructor(private http: HttpClient) {}
        
          ngOnInit() {
            // set the session identifier
            Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
            // create service that allows to recognize barcodes
            let barcodeService: Vintasoft.Shared.WebServiceControllerJS = new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftBarcodeApi");
        
            // create the barcode reader
            let barcodeReader: Vintasoft.Barcode.WebBarcodeReaderJS = new Vintasoft.Barcode.WebBarcodeReaderJS(barcodeService);
            // specify that Code39 barcode must be searched
            barcodeReader.get_Settings().set_BarcodeType(new Vintasoft.Barcode.WebBarcodeTypeEnumJS("Code39"));
        
            // create web image that references to a file "AllSupportedBarcodes.png" in directory "/UploadedImageFiles/SessionID/"
            let imageSource: Vintasoft.Shared.WebImageSourceJS = new Vintasoft.Shared.WebImageSourceJS("AllSupportedBarcodes.png");
            let image: Vintasoft.Shared.WebImageJS = new Vintasoft.Shared.WebImageJS(imageSource, 0);
        
            // send an asynchronous request for barcode recognition
            barcodeReader.readBarcodes(image, this.__readBarcodes_success, this.__readBarcodes_fail);
          }
        
          /**
           * Barcodes are recognized successfully.
           * @param {object} data Object with information about recognized barcodes.
           */
          private __readBarcodes_success(data: any) {
            if (data.success) {
              // get the barcode recognition result
              let barcodeRecognitionResults: any[] = data.results;
        
              let htmlMarkup: string = '';
              // if no barcodes found
              if (barcodeRecognitionResults.length == 0) {
                htmlMarkup = 'No barcodes found.';
              }
              // if barcodes are found
              else {
                htmlMarkup = barcodeRecognitionResults.length.toString() + ' barcodes are found.<br />';
                htmlMarkup += '<br />';
        
                // for each recognized barcode
                for (let i: number = 0; i < barcodeRecognitionResults.length; i++) {
                  // get the barcode recognition result
                  let barcodeRecognitionResult: any = barcodeRecognitionResults[i];
        
                  // output information about recognized barcode
                  htmlMarkup += '[' + (i + 1) + ':' + barcodeRecognitionResult.barcodeType + ']<br />';
                  htmlMarkup += '  Value: ' + barcodeRecognitionResult.value + '<br />';
                  htmlMarkup += '  Confidence: ' + barcodeRecognitionResult.confidence + '<br />';
                  htmlMarkup += '  Reading quality: ' + barcodeRecognitionResult.readingQuality.toFixed(2) + '<br />';
                  htmlMarkup += '  Threshold: ' + barcodeRecognitionResult.threshold + '<br />';
                  htmlMarkup += '  Region: ' +
                    'LT=(' + barcodeRecognitionResult.region.leftTop.x + ',' + barcodeRecognitionResult.region.leftTop.y + '); ' +
                    'RT=(' + barcodeRecognitionResult.region.rightTop.x + ',' + barcodeRecognitionResult.region.rightTop.y + '); ' +
                    'LB=(' + barcodeRecognitionResult.region.leftBottom.x + ',' + barcodeRecognitionResult.region.leftBottom.y + '); ' +
                    'RB=(' + barcodeRecognitionResult.region.rightBottom.x + ',' + barcodeRecognitionResult.region.rightBottom.y + '); ' +
                    'Angle=' + barcodeRecognitionResult.region.angle.toFixed(1) + '°<br />';
        
                  htmlMarkup += '<br />';
                }
              }
        
              let barcodeInformationElement: HTMLDivElement = document.getElementById("barcodeInformation") as HTMLDivElement;
              barcodeInformationElement.innerHTML = htmlMarkup;
            }
          }
        
          /**
           * Barcode recognition is failed.
           * @param {object} data Object with information about error.
           */
          private __readBarcodes_fail(data: any) {
            // show information about error
            alert(data.errorMessage);
          }
        
          title = 'angularapp1.client';
        }
        
        



      • Delete file "src\app\app.component.spec.ts" in "angularapp1.client" project - file is not necessary.

      • Open "src\proxy.conf.js" file in "angularapp1.client" project and specify that Angular aplication can have access to the ASP.NET Core Web API controller "/vintasoft/api/MyVintasoftBarcodeApi/" in "AngularApp1.Server" project:
        const { env } = require('process');
        
        const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
          env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'https://localhost:7200';
        
        const PROXY_CONFIG = [
          {
            context: [
              "/vintasoft/api/"
            ],
            target,
            secure: false
          }
        ]
        
        module.exports = PROXY_CONFIG;
        
        

    10. Run the "Angular and ASP.NET Core application" and see the result.