Scripting Sample 3

This sample demonstrates how to custom generate a barcode in HTML without calling the GetHTML2 method. It uses the EnumBarStart and EnumBarNext methods to get the positions and widths of the barcode bars and, based on this information, generates a sequence of HTML <IMG> tags. The result is the UPC-A barcode below:

Here's the ASP script for this:

<!-- #include file="ezbarvbs.inc" -->
<%
set bo = Server.CreateObject("Easybaro.Barcode")
bo.BarcodeType = bcUPCA
bo.Data = "12345678901"
bo.EnumBarStart 1
x = 0
do while bo.EnumBarNext(pos, width, style)
  'white space:
  response.write("<img align=top src=white.gif height=40 width=" & pos - x & ">")
  'black bar:
  if style and bcLongBar then
      response.write("<img align=top src=black.gif height=40 width=" & width & ">")
  else
      response.write("<img align=top src=black.gif height=35 width=" & width & ">")
  end if
  x = pos + width
loop
'we could optionally add a white space to the right of the barcode
%>
The above script illustrates the principle only. The latest Netscape Communicators (4.5/6x?) have a printing bug and may not scale images properly (images may not be scaled at all). The sample below, although more sophiscated, works around this bug.

<%
'object initialization code omitted - same as above
dim ht
bo.EnumBarStart 1
x = 0
do while bo.EnumBarNext(pos, width, style)

  'white space:
  response.write("<img align=top src=w")
  if pos - x > 10 then 
	response.write("10")
  else
	response.write(pos - x)
  end if
  response.write(".gif height=40 width=" & pos - x & ">")

  'black bar:
  if style and bcLongBar then
      ht = 40
  else
      ht = 35
  end if
  response.write("<img align=top src=b")
  response.write(width)
  response.write(".gif height=" & ht & " width=" & width & ">")

  x = pos + width
loop
%>