Skip to content

barcode-bakery/barcode-dotnet-1d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Barcode Bakery is library written in .NET Standard, PHP and Node.JS which allows you to generate barcodes on the fly on your server for displaying or saving.

The library has minimal dependencies in each language in order to be supported on a wide variety of web servers.

The library is available for free for non-commercial use; however you must purchase a license if you plan to use it in a commercial environment.

Installation

There are two ways to install our library:

  • With PowerShell, get the file from NuGet, run the following command:
PM> Install-Package BarcodeBakery.Barcode1D

Requirements

  • .NET Standard 2.0
  • .NET Core 2.0+
  • .NET Framework 4.6.1+

Example usages

For a full example of how to use each symbology type, visit our API page.

Saving a Code 128 to a MemoryStream

public static async Task CreateAsync(string filePath, string? text = null)
{
    // Loading Font
    var font = new BCGFont("Arial", 18);

    // Don't forget to sanitize user inputs
    text = text?.Length > 0 ? text : "a123";

    // The arguments are R, G, B for color.
    var colorBlack = new BCGColor(0, 0, 0);
    var colorWhite = new BCGColor(255, 255, 255);

    Exception? drawException = null;
    BCGBarcode? barcode = null;
    try
    {
        var code = new BCGcode128();
        code.SetScale(2); // Resolution
        code.SetThickness(30); // Thickness
        code.SetForegroundColor(colorBlack); // Color of bars
        code.SetBackgroundColor(colorWhite); // Color of spaces
        code.SetFont(font); // Font
        code.SetStart(null);
        code.SetTilde(true);
        code.Parse(text); // Text
        barcode = code;
    }
    catch (Exception exception)
    {
        drawException = exception;
    }

    var drawing = new BCGDrawing(barcode, colorWhite);
    if (drawException != null)
    {
        drawing.DrawException(drawException);
    }

    // Saves the barcode into a MemoryStream
    var memoryStream = new System.IO.MemoryStream();
    await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, memoryStream);
}

Saving the image to a file

Replace the last line of the previous code with the following:

// Saves the barcode into a file.
await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, filePath);

This will generate the following:

Supported types

Other libraries available for purchase

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages