This example repository will allow you to generate MaxiCode barcodes. You can find more information on our Barcode Bakery website.
This is based on the barcode MaxiCode library.
The library is not free, you must purchase a license in order to obtain it.
There are two ways to install our library:
- With the command line, get the file from GitHub, run the following command.
PM> dotnet add PROJECT package BarcodeBakery.BarcodeMaxiCode --version 3.0.1
- Or, download the library on our website, and follow our developer's guide.
- .NET Standard 2.0
- .NET Core 2.0+
- .NET Framework 4.6.1+
For a full example of how to use each symbology type, visit our API page.
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 : "MaxiCode";
// Label, this part is optional
var label = new BCGLabel();
label.SetFont(font);
label.SetPosition(BCGLabel.Position.Bottom);
label.SetAlignment(BCGLabel.Alignment.Center);
label.SetText(text);
// 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 BCGmaxicode();
code.SetScale(3);
code.SetMode(4);
code.SetQuietZone(true);
code.SetForegroundColor(colorBlack); // Color of bars
code.SetBackgroundColor(colorWhite); // Color of spaces
code.AddLabel(label);
code.Parse(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);
}
Replace the last line of the previous code with the following:
// Saves the barcode into a file.
await drawing.FinishAsync(BCGDrawing.ImageFormat.Png, filePath);