dLSoft  barcode & labelling software     

Barcodes on web servers

Barcodes can appear in web browsers as images created on the server. Server-side images are created on the server and transmitted as graphic files to the browser - just like any other graphic or text.

The best solution is for creating barcodes for ASP.NET or HTML is to create a complete graphic of the barcode and transmit it from memory (ie. not requiring writing to the server's disk). Barcode Server is an application that runs on Microsoft Internet Information Server (IIS) and generates barcode images which may be requested by a variety of applications, including web browsers, Microsoft Office applications, Crystal Reports, etc. – in fact any application that can use a link of the form http://...... As the source of an image.

Another technique is provided by the dBarcode.NET components which provide managed-code components for ASP.NET pages.


Barcode images for HTML pages

Barcode image can be incorporated into web pages in several ways. For simple HTML pages the links to the server can be placed within <IMG> tags.

So, for example, the web page image shown below:

A  web page containing barcodes generated by Barcode Server for IIS
Click to enlarge

is generated entirely from the HTML code:

<H1>dLSoft Barcode IIS server</H1>
For barcodes on web pages.

<p>This page uses the references similar to <br>
"IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=0&Xunit=16&Data=12345""<br>
to display barcodes on this page.
You can view the actual call by selecting View Source for this page.</p>

<p><IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=8&Xunit=20&Data=1234567890">
<IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=86&Xunit=40&Data=www.Conso.com">
<IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=12&Xunit=13&BarcodeHeight=22&

<p>The full source code of the barcode.aspx servlet is included in the Samples folder of the products installation directory</p>

<p><IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=0&Xunit=16&Data=1234">
<IMG SRC="http://localhost/IISnet/barcode.aspx?CodeType=81&Xunit=40&Data=www.Conso.com">
dLSoft Barcode IIS server may be licenced for 1D barcodes, 2D barcodes or both.

Creating barcode images on ASP.NET pages

There are many possible approaches to generating barcode images for ASP.NET pages. Whatever method is chosen it is important to ensure that the image is created at a higher graphics resolution than the normal 96 dpi used for web images - because the width of the bars is important.

Using a dBarcode.NET component

One method, suitable for use when the barcode is to be data-dependent, is to use two aspx files, one which creates a memorystream barcode image using one of the dLSoft dBarcode.NET components and then uses a dummy ASP.NET page as the SRC for an IMG tag to display the image at the correct size, eg.

<script language="vb" runat="server">
sub Page_Load(Sender As Object, E As EventArgs)
m_barcode.Unit = GraphicsUnit.Inch
m_barcode.XUnit = 0
m_barcode.BarcodeHeight = tht     ' desired height in inches
m_barcode.BarcodeWidth = twd    ' desired width in inches
m_barcode.CodeTypeValue = 8
m_barcode.caption = Session("xx")
if Session("ms").Length>0 then
Session("ht")=m_barcode.ImageHeight*96/300 ' adjust size for the desired image resolution
end if
<H1>dLSoft dBarcode.NET - on ASP.NET</H1>
<IMG SRC="page2.aspx" HEIGHT=" <% =Session("ht") %> " WIDTH=" <% =Session("wd") %> ">
<p> dBarcode.NET components can generate barcode images in BMP, GIF, PNG, JPG, TIF and WMF formats, and for more than 50 barcode types.

The Session variables ht and wd contain the actual sizes at which the barcode image is to be drawn on the web page. These are calculated when the page is loaded and used when the IMG SRC calls the second page.

The second file (page2.aspx) serves up the image at the correct size, eg.

A working sample is included with each dBarcode.NET component distribution, and the technique may be seen in operation at our Barcodes Online service.


The method described above is the preferred method of generating barcode images in ASP.NET, but it can be more convenient in some cases to use a servlet that returns an image in response to a single HTTP GET call.

The SetParam() and Pic() methods are available within the dBarcode.NET components to facilitate this approach. The following ASP.NET file (barcode.aspx) illustrates this:

<%@ Page Language="VB" aspcompat=true %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.SessionState" %>

<script language="vb" runat="server">
sub Page_Load(Sender As Object, E As EventArgs)
Dim loop1, loop2,res As Integer
Dim values as ArrayList= new ArrayList()
Dim coll As NameValueCollection
Dim arr1(), arr2() As String
Dim m_barcode = New AbcnetLib.Abcnet()
arr1 = coll.AllKeys

if Not IsPostBack Then
   'These are the default values for the barcode parameters
   'and may be changed if required
   Dim m_Font As New Font("Arial", 10, FontStyle.Regular) m_barcode.Font=m_font
   m_barcode.CodeTypeValue = 9 ' code 128
   m_barcode.Unit = GraphicsUnit.Millimeter
   m_barcode.XUnit = 0
   m_barcode.BarcodeHeight = 16
   m_barcode.BarcodeWidth = 30
   For loop1 = 0 To arr1.GetUpperBound(0)
      arr2 = coll.GetValues(loop1)
      next loop1
end if
end try
end sub

This file may be called from an application or a web page using a link of the form:

http:// server/barcode.aspx?CodeType=9&Unit=in&BarcodeHeight=0.5&Xunit=12 &Data=1234567890

and the call returns the memory stream barcode image.

Note that properties that are likely to remain constant for many barcodes are best set in the body of the servlet, leaving only those properties that will change to be passed in the http call. The values passed in the http call overwrite those set in the servlet body.