Adding Barcodes to a Web Site using ZXing

Barcodes are defined as “…an optical machine-readable representation of data relating to the object to which it is attached.” (per Wikipedia). If you want to know which industry used “barcodes” first than scan the barcode at the bottom of this article, you could also read it in my code section (not as much fun). It began around the 1960 and has ballooned to now include barcodes on everything from apples to zebras (not really) but zebras do have stripes.

Anyway barcodes are great to use for just about anything. I mostly use them on documents when they are printed but can contain just about anything. There is a great .dll library for .net that helps in adding barcodes to your page at runtime. It is called ZXing.Net and will handle QR Code, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar and a few others.

Scott Hanselman has a great article on using this barcode in a WPF application but I am going to use a simple web form example. Once you understand how to implement this you can use it for anything.

I will also give you a few thoughts on barcoding at the end….Let’s get started.

1. Launch VS 2012 and create a new web blank project.

2. Add a reference to the zxing.dll (get it here)

3. Create a blank web form and add this to the page.

4. In the code behind on the blank web form add this.

[code language=”vb”]

Imports System.IO
Imports ZXing
Imports ZXing.QrCode
Imports System.Drawing.Imaging

Public Class WebForm1
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim qrCode As New QRCodeWriter()
Dim qrValue As String = "Railroads"

Dim BarcodeWriter As New ZXing.BarcodeWriter

BarcodeWriter.Format = ZXing.BarcodeFormat.QR_CODE
‘BarcodeWriter.Format = ZXing.BarcodeFormat.CODE_39
BarcodeWriter.Options.Height = 200
BarcodeWriter.Options.Width = 400
BarcodeWriter.Options.Margin = 1

Using bitmap = BarcodeWriter.Write(qrValue)
Using stream = New MemoryStream()
bitmap.Save(stream, ImageFormat.Gif)

Dim img = New StringBuilder()

img.Append("<img alt="" src=" + [String].Format(" />")

End Using
End Using
End Sub

End Class


Some points to remember when using barcodes.

  1. 1. In closing keep in mind that each type of barcode does have some limitations
  2. 2. If you are using QR code (designed for smart devices) then make sure where you are sending them have a mobile-UI otherwise their experience will be less than pleasant.
  3. 3. I use a QR on business cards and such which directs them to a page like. ( Then I use google analytics to track that they came from my business card and then do an automatic redirect to I realize this method is not perfect but it does help understanding where your customers are coming from. You could set up one for each of your marketing methods.
  4. 4. Realize that barcodes are to be read by computer and not humans.
  5. 5. If you don’t want to build yours “on-the-fly” then you can build it online here

Adding QR Codes to your site

Link to VS2012 Project:Barcoding

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , | Posted under Programming/Coding | RSS 2.0

Author Spotlight

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *