VintaSoft Barcode .NET SDK 15.3: Documentation for Web developer
In This Topic
    Generate barcode 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 generate barcode 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 to ASP.NET Core Web application.

      Add references to the nuget-packages "Vintasoft.Barcode", "Vintasoft.Barcode.SkiaSharp" and "Vintasoft.Barcode.AspNetCore.ApiControllers" to the "AngularApp1.Server" project.
      Comment: Reference to "Vintasoft.Barcode.SkiaSharp" nuget-package is necessary only if SDK should draw text value of barcode on barcode image. "Vintasoft.Barcode.ImageSharp" nuget-package can be used instead of "Vintasoft.Barcode.SkiaSharp" nuget-package.

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

      • 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 that VintaSoft Barcode .NET SDK should use SkiaSharp library for drawing of 2D graphics.

      Open file "Program.cs" in "AngularApp1.Server" project and add code line "Vintasoft.Barcode.SkiaSharpAssembly.Init();" at the beginning of file:

      Here are source codes of Program.cs file:
      // specify that VintaSoft Barcode .NET SDK should use SkiaSharp library for drawing of 2D graphics
      Vintasoft.Barcode.SkiaSharpAssembly.Init();
      
      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();
      
      
    5. "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.
    6. "angularapp1.client" project: Compile the solution for restoring TypeScript-dependencies in "angularapp1.client" project.

    7. "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"
        ]
        ...
        

    8. "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 generated barcode image) to the "app.component.html" file:
        <h1>Angular Barcode Generator Demo</h1>
        
        <img id="barcodeImage" src="" />
        
        



      • 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() {
            // generate image of QR barcode with value "12345"
            this.generate2dBarcodeImage("QR", "12345");
          }
        
          /**
           * Generates 1D barcode image.
           * @param barcodeType Barcode type.
           * @param barcodeValue Barcode value.
          */
          public generate1dBarcodeImage(barcodeType: string, barcodeValue: string) {
            // set the session identifier
            Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
            // create web service that allows to generate barcode
            let barcodeService: Vintasoft.Shared.WebServiceJS = new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftBarcodeApi");
        
            // create the barcode writer
            let barcodeWriter: Vintasoft.Barcode.WebBarcodeWriterJS = new Vintasoft.Barcode.WebBarcodeWriterJS(barcodeService);
        
            // create the barcode writer settings for generating 2D barcode
            let barcodeWriterSettings: Vintasoft.Barcode.Web1DBarcodeWriterSettingsJS = new Vintasoft.Barcode.Web1DBarcodeWriterSettingsJS();
            // specify that barcode writer must generate QR barcode image
            barcodeWriterSettings.set_BarcodeType(new Vintasoft.Barcode.WebBarcodeTypeEnumJS(barcodeType));
            // specify the QR barcode value
            barcodeWriterSettings.set_Value(barcodeValue);
        
            // specify settings for barcode writer
            barcodeWriter.set_Settings(barcodeWriterSettings);
        
            // send an asynchronous request for getting barcode image as Base64 string
            barcodeWriter.getBarcodeAsBase64Image(this.__writeBarcode_success, this.__writeBarcode_failed);
          }
        
          /**
           * Generates 2D barcode image.
           * @param barcodeType Barcode type.
           * @param barcodeValue Barcode value.
          */
          public generate2dBarcodeImage(barcodeType: string, barcodeValue: string) {
            // set the session identifier
            Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
            // create web service that allows to generate barcode
            let barcodeService: Vintasoft.Shared.WebServiceJS = new Vintasoft.Shared.WebServiceControllerJS("vintasoft/api/MyVintasoftBarcodeApi");
        
            // create the barcode writer
            let barcodeWriter: Vintasoft.Barcode.WebBarcodeWriterJS = new Vintasoft.Barcode.WebBarcodeWriterJS(barcodeService);
        
            // create the barcode writer settings for generating 2D barcode
            let barcodeWriterSettings: Vintasoft.Barcode.Web2DBarcodeWriterSettingsJS = new Vintasoft.Barcode.Web2DBarcodeWriterSettingsJS();
            // specify that barcode writer must generate QR barcode image
            barcodeWriterSettings.set_BarcodeType(new Vintasoft.Barcode.WebBarcodeTypeEnumJS(barcodeType));
            // specify the QR barcode value
            barcodeWriterSettings.set_Value(barcodeValue);
        
            // specify settings for barcode writer
            barcodeWriter.set_Settings(barcodeWriterSettings);
        
            // send an asynchronous request for getting barcode image as Base64 string
            barcodeWriter.getBarcodeAsBase64Image(this.__writeBarcode_success, this.__writeBarcode_failed);
          }
        
          /**
           * Barcode is generated successfully.
           * @param data Object that stores response from barcode service.
           */
          private __writeBarcode_success(data: any) {
            if (data.success) {
              let barcodeImage: string = data.barcodeImage;
              let barcodeImageElement: HTMLImageElement = document.getElementById("barcodeImage") as HTMLImageElement;
              barcodeImageElement.src = barcodeImage;
            }
            else {
              alert(data.errorMessage);
            }
          }
        
          /**
           * Barcode generation is failed.
           * @param data Object with information about error.
           */
          private __writeBarcode_failed(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;
        
        

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