23
  • 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?
tshepang
  • 12,111
  • 21
  • 91
  • 136
ACP
  • 34,682
  • 100
  • 231
  • 371
  • You only need to send the *code* to a barcode printer to print the barcode, you don't need to render it actually (barcode printer should do it for you). – vgru Jan 04 '10 at 09:02
  • Related: http://stackoverflow.com/questions/4477132/create-barcode-with-text-image-not-pdf-using-itextsharp – BlueRaja - Danny Pflughoeft May 18 '12 at 16:09

5 Answers5

25

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.

Thomas Koelle
  • 3,416
  • 2
  • 23
  • 44
Rune Grimstad
  • 35,612
  • 10
  • 61
  • 76
  • 2
    Another library to generate code 128 barcode image from string: [GenCode128](http://www.codeproject.com/KB/GDI-plus/GenCode128.aspx) – Endy Tjahjono Jun 25 '11 at 02:26
2

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

Yes, it is. There are quite a lot of frameworks that do it - either as a font or an image.

Is there any built-in classes for generating barcodes in asp.net?

No, but this c# project on github allows a string to be converted into an image (even multiple barcode types). All you need to do then is display the image in your application, just like any other image.

Is it possible to detect a barcode printer connected with a system?

Yes, in a WinForm application, for example, you could use System.Drawing.Printing.PrinterSettings.InstalledPrinters.

Joe Ratzer
  • 18,176
  • 3
  • 37
  • 51
  • While the codeplex lib of the other answer is old, and, because CodePlex is closing, moved to github in 2017, and since not updated, this github project is active, and has more stars. This lib includes a nice standalone gui demo app. Just 1-D though. No 2-D "bar"-codes like QR – Roland Apr 20 '21 at 12:05
1

to detect if you have printer installed then you may simply enumerate available printers using:

 System.Drawing.Printing.PrinterSettings.InstalledPrinters
Eugene
  • 2,820
  • 19
  • 24
0

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

darren
  • 475
  • 4
  • 15
-1

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#.