Search code examples
c#visual-studio-2013barcodebarcode-printingean-13

How to draw an EAN-13 barcode in Visual C#


What's the most basic way of drawing EAN-13 barcodes in C# (using Visual Studio 2013) for printing?

I would prefer to include a namespace providing me with the tools to create and output the barcode.


Solution

  • The easiest library to use IMHO is Aspose BarCode.NET. You can find examples here

    The library does cost money, but works well enough that for us, it was worth it.

    // Create an instance of BarCodeBuilder
    BarCodeBuilder builder = new BarCodeBuilder();
    
    // Set the symbology type
    builder.SymbologyType = Symbology.EAN13;
    
    // Set the codetext
    builder.CodeText = "test-123";
    
    // Get the barcode image
    Image img = builder.BarCodeImage;
    

    Now you can do whatever you want with the image, like save it to a file, or write to a memory stream, etc.:

    img.Save("path", System.Drawing.Imaging.ImageFormat.Bmp);