0

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.

Dominique
  • 1,080
  • 14
  • 29
  • 4
    Using an EAN13 font is the easiest – Alex K. Sep 17 '14 at 14:21
  • @AlexK. Of course you'd have to do the encoding yourself, i.e. translating numbers to symbols, calculating checksums, etc. – Thorsten Dittmar Sep 17 '14 at 14:36
  • @AlexK, Thorston is right... you can't just print using an EAN-13 font as printing 13 numbers just shows 13 short bar codes instead on 1. I was down that road a few hours ago pulling out my hair until I figured this out. – Dominique Sep 17 '14 at 14:40
  • Yes you will always need to apply the correct encoding, I thought you were after alternatives to rendering the glyphs manually – Alex K. Sep 17 '14 at 14:42
  • 1
    @Dominique http://www.codeproject.com/Articles/10162/Creating-EAN-Barcodes-with-C http://community.bartdesmet.net/blogs/bart/archive/2006/09/20/4459.aspx both within the first 5 results from google – Thewads Sep 17 '14 at 15:08
  • @Thewads congratulations on only taking 5 minutes to find a link to something outdated (2005) that has been mentioned by someone else... oh, did I mention I told you I'm using something recent? – Dominique Sep 17 '14 at 15:12
  • @Thewads and your second link is from 2006... don't know what that runs on... maybe you should consider an upgrade! – Dominique Sep 17 '14 at 15:15
  • 1
    @Dominique failing to see how the version of VS you are using is at all relevant, not like that changes the logic of how to create barcodes but ok. Use logic, fixup any changes between .net version etc – Thewads Sep 17 '14 at 15:27

1 Answers1

2

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);
mfanto
  • 14,168
  • 6
  • 51
  • 61
  • 1
    Thank you for the advice, but I want something free... sorry for not mentioning that. – Dominique Sep 17 '14 at 14:41
  • 1
    [Here is](http://www.codeproject.com/Articles/10162/Creating-EAN-Barcodes-with-C) a possible solution already. Requires some work to integrate into your project, but it's a simple algorithm to generate an EAN-13 in GDI (for printer output for example) – test-in-prod Sep 23 '14 at 15:56