0
votes

We have several reports created with the crystal reports included with Visual studio 2008. We now need to include barcodes into these reports. Can this be done with just visual studio 2008 and its included version of crystal reports? How about VS 2010 (after downloading the crystal reports for visual studio 2010 from business objects).

Is there any other way to do this for free or do we absolutely have to buy the crystal reports or third party software to do this ?

2
I thought this can be done by generating the barcode as an image file in a separate library (which we already have) and embedding that image on the crystal report. However, when I insert a picture object into the report (by selecting an image file) and then editing the pictures hyperlink formula to get the file name from the dataset, it still shows only the image set at design time. Does any one know if the formula for image location works in crystal reports or if there is a work around? Also, is there any other way to embed barcodes.DevByDefault

2 Answers

0
votes

I have found the following solution on one of the forums but I dont remember which one, (please tell me if you are know the original post and I will link to it.)

Here are the steps required to add a barcode on crysal report.

1) Add a column of type byte array to the dataset used in the report. 2) Open the crytal report and verify the database so the newly added column gets updated in the crytal report. 3) In the crystal designer, drag the new database column on the design surface and drop it on the desired location. 4) In the method that generates the report, add the following code to stuff the content of the barcode image into the new column.

Dim fsImageFile As FileStream
Dim brReader As BinaryReader
fsImageFile = New FileStream(strBarcodeImageFilePath, FileMode.Open)
brReader = New BinaryReader(fsImageFile)

Dim bImageByte(Convert.ToInt32(fsImageFile.Length + 1)) As Byte
bImageByte = brReader.ReadBytes(Convert.ToInt32(fsImageFile.Length))

drMyCrystalReport.BarcodeImage = bImageByte

In the above example drMyCrystalReportis the datarow for the dataset and BarcodeImage is the column that was added to the dataset. This code adds the content of the image file to the database column and crystal reports displays that content when this column is added to it.

0
votes

It depends on the barcode symbology you want to print. For a Code 39 barcode, you just need to enclose your string between a pair of "*" characters and use a Code39 font; it is self-checking so needs no further processing. I use Free3of9.ttf which works fine.

Code 128 requires a check digit and needs a function that calculates the correct character (which is font-dependent) that will be used at the end of the string to form a complete barcode. There are a few of these fonts around, with libraries of functions for various languages. One of these is from Brian Dobson (FreeBarcodeFonts) and appears to be a fairly complete solution, including a DLL for use with Crystal Reports on Windows.

I have no comment about your idea of using dynamically generated image files, as Crystal Reports is a pretty obscure tool. Sounds plausible, though, even if you did it through a stored procedure on your database.

Other symbologies are available, most commercial. Do a web search for "barcode font" and your symbology name to get lots of results.