How to generate barcode from a string using C#?

Viewed 59430
  • Is it possible to generate barcode from a string using c#?
  • Is there any builtin classes for generating barcodes in asp.net?
  • Is it possible to detect a barcode printer connected with a system?
5 Answers

Yep. Of course it is possible. :-)
As far as I know there are two ways to generate bar codes:

  1. Using a special bar code font (try to google for "barcode font free")
  2. Render the bar code to an image and display that (try using the Barcode Rendering Framework available on github)

In response to your updated question about detecting barcode printers:
I think a barcode printer will show up as a regular printer on your system. At least that is how the devices I have played with have worked.
This means that you can detect a specific barcode printer by enumerating the installed printers on the system and looking for the specified device, but in most cases I would suggest that you let the user specify the printer himself using either the standard print dialog or using a custom dialog.

Is it possible to generate barcode from a string using c#?

If you want a C# barcode generator that can create your desired barcode type in a single line of code, you can use IronOcr.

// Create A Barcode in 1 Line of Code
BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.QRCode).SaveAsJpeg("QR.jpg");

The result can be exported as images, bitmaps, binary data, streams, stand-alone HTML image tag, Data Uris, PDFs or HTML.

If you need more advanced barcodes, QR Codes with logos - these are also supported.

Disclaimer: I work for Iron Software, makers of IronBarcode

Yes, it's possible using C#.

No, there are no built-in classes. But there are 3rd-party libraries.

For example, a free cross-platform C# library Gehtsoft.Barcodes for generation of different types of barcodes and QR codes from string into image. You can find it in nuget.

Moreover, you can generate barcode directly into PDF document with Gehtsoft.PDFFlowLib.Barcodes C# library (it uses Gehtsoft.Barcodes library automatically). It can also be downloaded from nuget.

DocumentBuilder.New()
    .AddSection()
        .AddParagraph()
            .AddBarcode("4810151021665", BarcodeType.EAN_13)
.ToDocument()
    .Build("Result.pdf");

generated barcode

Using this libraries you can generate barcodes UPC-A, EAN-13, EAN-8, GS1-128 (Code Sets A, B, and C) and QR codes (variants 1-40, four levels of error correction available).

Here is a tutorial with many examples: Adding barcodes.

Note, that Gehtsoft.PDFFlowLib.Barcodes library is an extension of PDFFlow library for generation PDF documents using C#.

Related