SQLServerCentral Article

Generating a Bar Code

,

Sometimes you have to start from beginning, almost from a DOS, especially if you task sounds like "make a simple barcode generator". Naturally, I started with most complicated ideas, to make a RTF (it is not short for read the f*** manual) or a PDF as an add-on to previous article. Other ideas were to create HTML tables with cells black & white backgrounds, or to use GIFs but it is almost complicated like drawing shapes in RTFs or PDFs. But first of all..

Why barcode? We are working with Documentum, so electronic documents are our objects. When you have batch scanning there is need to connect images with attributes in databases. If you have scanning tool you can scan papers into the electronic format but there has to be some link to other data and that it is barcode. Just paste some label with barcode on paper and after scanning use some tool like JavaOCR for OCRing and you can even index documents. Barcode is very good for OCRing. This example does not need barcode reader, but if you want to manage you CD/DVD collection you will need barcode reader like they do in the shops.

And now some technical stuff. Testing environment is: Win 2k, MS SQL server 2000, IE 6.

There is a sql script with one created table psoBarCode39, two functions (hex, checksum39 - for control digit) and main procedure psoCode39. The procedure will produce html file on C disk (C:\PsoCode39.htm).IE is needed for penning because Microsoft font embedding technology is used. Sometimes I get numbers instead of barcode so it is recommended to test results in print preview window. Produced barcode is Barcode 39. Allowed characters are :'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.(space)$/+%'.

Download SQL code.

Hope you are familiar with next syntax from SQL BOL.

psoCode39

Create HTML page with Barcode39.

Syntax

psoCode39 [@tablex=]tablex,

[@tabley=]tabley,

[@pages=]pages,

[@height=]height,

[@barcodeSize=]barcodeSize,

[@textSize=]textSize,

[@prefix=]'prefix',

[@startValue=]startValue,

[@checkdigit=]checkdigit

Arguments

[@tablex=]tablex,

Is the number of columns int, with no default,

[@tabley=]tabley,

Is the number of rows int, with no default,

[@pages=]pages,

Is the number of pages int(visible only in print preview window), with no default,

[@height=]height,

Is the height of rows int, with no default.

[@barcodeSize=]barcodeSize,

Is the size of barcode int, with no default.

[@textSize=]textSize,

Is the size of text description bellow barcode int, with no default.

0 means no text description.

[@prefix=]'prefix',

Is the text in front of barcode varchar(10), with no default.

'' means no prefix,

[@startValue=]startValue,

Is the number with starting value for auto generate barcode with step 1,

0 means take values from table psoBarCode39, int, with no default.

[@checkdigit=]checkdigit

If 1 check digit is added at end of barcode,

other means no check digit int, with no default.

Example

Values
Created Barcode
Description
EXEC psoCode39 3,3,1,70,60,10,'',1000000,0
1000000 1000001 1000002

1000003 1000004 1000005

1000006 1000007 1000008

auto generated barcode
EXEC psoCode39 2,2,1,70,60,10,'',1000000,1
10000001 10000012

10000023 10000034

with check digit
EXEC psoCode39 2,1,1,70,60,10,'PSO',1000000,1
PSO1000000Z PSO1000001-
with prefix
INSERT INTO psoBarCode39 VALUES ('FIRST')

INSERT INTO psoBarCode39 VALUES ('SECOND')

EXEC psoCode39 2,1,1,70,60,10,'',0,1

FIRSTV SECONDS
your data
Values
Preview
EXEC psoCode39 2,1,1,70,60,10,'PSO',10,1
EXEC psoCode39 4,10,2,70,60,10,'PSO',10,1

Remarks

Some additional settings could be done with IE menu File- Page setup. Delete anything from header and footer. Update margins as needed. Be careful with function invocation in the main procedure.

See Also my previous article on creating PDFs.

Resources

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating