Barcode, labelling and utility 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 IIS servers is to create a complete graphic of the barcode and transmit it from memory (ie. not requiring writing to the server's disk). This also simplifies the code sent to the browser - which merely receives the name of the graphic with <img> tags. For this solution the Barcode IMG Servers for IIS are ideal for ASP pages, while the dBarcode.NET components provide managed-code components for ASP.NET pages.

Alternatively the barcode may be transmitted as a string of characters to be displayed in a specified font - even though that font is not installed on the browser's computer. To see how this operates see Barcode fonts on web pages.


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.Font=m_Font
m_barcode.Orientation=0
m_barcode.AutoCheckdigit=TRUE
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")
Session("ms")=m_barcode.sBarcode(300,300,System.Drawing.Imaging.ImageFormat.Png)
if Session("ms").Length>0 then
Session("ht")=m_barcode.ImageHeight*96/300 ' adjust size for the desired image resolution
Session("wd")=m_barcode.ImageWidth*96/300
end if
</script>
</head>
<BODY>
<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.
</BODY>
</HTML>

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.
<%@ LANGUAGE="VB"%>
<%
Response.ContentType="image/png"
Response.BinaryWrite(Session("ms").GetBuffer())
%>

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


Barcode IMG Server for IIS ASP

A method suitable for ASP pages is to use one of the Barcode IMG Servers for IIS. The Barcode IMG Servers for IIS may be used to include barcode images on ASP pages, and a sample application is included with the distributions.

The IMG Servers use a Barcode Object which generates a graphic image of the barcode. The Objects are created using Server.CreateObject("B1barcode.Control") for the ID server or Server.CreateObject("B2barcode.Control") for the 2D server.

The Barcode Object has a number of properties which may be set to specify characteristics of the barcode required, and these are described in detail in the reference section. The object also has three properties which may be read to form the barcode image: PictureHeight and PictureWidth (which specify the sizes of the image) and the Pic() property which is a Variant that can be used to display the image in a web browser.

A minimal sample (which just creates a fixed barcode) would be as shown below, and several sample pages are included in the "samples" subdirectory of the product's installation directory. There are three basic components:

1. GLOBAL.ASA

The global.asa file contains the code for creating the object and setting properties, which will not change while the user, is viewing any ASP pages on your site:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>

Dim vntStream

Sub Session_OnStart

Set Session("m_barcode") = Server.CreateObject("B1barcode.Control")
Session("m_barcode").Serial=”12345”
Session("m_barcode").CodeType=0
Session("m_barcode").Xunit=20
Session("m_barcode").ImageHeight=2000

End Sub
</SCRIPT>

2. BARCD.ASP

This is a simple file that contains the code to return the image at the point it is required. The file content is typically:

<%@ LANGUAGE="VBSCRIPT" %>
<%
Response.ContentType="image/gif"
Response.BinaryWrite(Session("vntStream"))
Response.End
%>

And may specify the content type as being one of the following:

GIF image = image/gif
PNG image = image/x-png
WMF image = image/x-wmf

3. An ASP page

This is the page that returns HTML to the users browser and will include the barcode:

<%@ LANGUAGE="VBSCRIPT" %>
<%
Function Barc(xx) ‘ this is the function that returns the barcode picture
Response.Buffer=TRUE
Session("m_barcode").Caption=xx
Session("vntStream")=Session("m_barcode").Pic(0)
ht=(Session("m_barcode").PictureHeight)
Response.Write("<IMG SRC=""barcd0.asp"" HEIGHT=""" & ht & """>")
End Function
%>

<HTML>
<BODY>
<H1>dLSoft Barcode IMG Server</H1>

……….

<% xx="501234567890"
Barc(xx) ‘ this is the call to obtain the barcode picture
%>

…………….

</BODY>
</HTML>

Those familiar with ASP coding will realise that there are many ways of obtaining the same result!

Barcode IMG Server for IIS supports the use of GIF, PNG or WMF images, the type of image generated being determined by the parameter of the Pic(i) call, for which i=0 gives GIF, i=1 gives PNG and i=2 gives WMF images. PNG images are smaller than the corresponding GIF images, but (at the time of writing) some older versions of the popular browsers have problem printing PNG images. WMF images are suitable for display on Microsoft Windows clients only.


Sites operated by DL Technology Ltd                            barcode software       barcode fonts                  
E-mail: webmaster@dlsoft.com                      [Product index] [Site index
15/06/2008

dLSoft is a registered trade mark of DL Technology Ltd, a company registered in England number 3615271

Award-winning publisher 2006    dLSoft - Award-winning publisher 2006 & 2007     Award-winning publisher 2007