March 18th, 2010, 03:41 PM
How to create barcodes that must fit a given size or area in Reporting Services
- Neodynamic Barcode Professional 3.0 for Reporting Services
- Microsoft .NET Framework 1.1 or greater
- Microsoft Visual Studio .NET 2003, Microsoft Visual Studio 2005 or SQL Server Business Intelligence Development Studio
- Microsoft SQL Server 2000/2005 Reporting Services or Visual Studio Local Reports RDLC
It's very common to need to create a barcode image in order it fits a given area, for instance: "The barcode must fit an area of size 1.5 inch x 1 inch". Take a look the following scenarios to learn how to accomplish this kind of requirements.
If you are using Reporting Services 2000 or Visual Studio Local Reports RDLC
So, supposing you want to create a barcode image that must fit an area of size 1.5 inch x 1 inch; in order to accomplish that you must:
- Set the AutoSize property to True, the desired area size to FitBarsAreaWidth and FitBarsAreaHeight properties, and a significant image resolution value such as 300 in the Dpi property of the Barcode Professional instance used in the VB.NET function in the Code section of your report. In addition, the following properties settings are mandatory for fitting feature: QuietZoneWidth, TopMargin, and BottomMargin must be set to 0 (zero), Text must be set to an empty string, and DisplayCode must be set to False. Take a look at the following example:
NOTE: Remember that FitBarsAreaWidth and FitBarsAreaHeight properties as well as any dimension related properties such as BarWidth, BarHeight, etc; are measured in INCHES.
LIMITATION: In these reporting scenarios (Reporting Services 2000 or Visual Studio Local Reports RDLC), there's a "limitation" when working with fitting feature: you cannot display any readable texts on the barcode! In order to bypass this limitation you may add a TextBox control displaying the value to encode just below the Image control that will hold the barcode image.
Public Function GetBarcode(ByVal valueToEncode As String) As Byte()
objBarcode.Code = valueToEncode
objBarcode.Symbology = Neodynamic.ReportingServices.Symbology.Code128
'Settings for fitting the barcode image to the desired area
objBarcode.AutoSize = True
objBarcode.Dpi = 300
objBarcode.FitBarsAreaWidth = 1.5
objBarcode.FitBarsAreaHeight = 1
objBarcode.QuietZoneWidth = 0
objBarcode.TopMargin = 0
objBarcode.BottomMargin = 0
objBarcode.Text = ""
objBarcode.DisplayCode = False
- Set the target area size in the Size property, and the Sizing property to FitProportional of the Image control used to display the barcode image on the report surface i.e. the same Image control which Value property is set up with an expression invoking the GetBarcode function.
The Image report item which will display the barcode image generated by GetBarcode function
For instance, if the value "1234567890" is passed to the hypothetical GetBarcode function, then you'll get the following barcode image which fits the desired area (1.5 inch x 1 inch):
The output barcode image fitting the desired area
If you are using Reporting Services 2005
In this reporting scenario, the Barcode Professional Report Item is placed on the report surface where you want to display the barcode image. If Barcode Professional is used as a Report Item, then a few main properties must be specified. Given the previous hypothetical example, just set up the FitBarsAreaToSize property in the Visual Studio's Properties Window (figure 1) or through out the Barcode Builder form under Font & Format tab in the Image Settings section (figure 2).
Figure 1: FitBarsAreaToSize property
Figure 2: The Width and Height of the target area in Barcode Builder
When you set up the FitBarsAreaToSize property it will take precedence over any change you make on other dimension properties such us BarWidth, BarHeight, etc. You must set up the FitBarsAreaToSize property to an empty value in order to disable the "fitting" feature.
When you set up this target area values, Barcode Professional will automatically calculate the new dimensions for the barcode in order it fits the desired size. Just keep in mind the following points about the target area:
- The target Width includes the whole barcode bars width plus left and right Quiet Zones (QuietZoneWidth property)
- The target Height includes the barcode bar's height only
The mentioned points want to mean that, for example, if you want to encode the data 1234567890 in Code 128 at 300DPI in order it fits an area of size 1.5 inch x 1 inch and if you have set up a Quiet Zone Width of 0.1 inch, then you'll get the following barcode.
The output barcode image fitting the desired area and honoring left & right quiet zones!
However, if you wanted to fulfill the whole target area with the barcode only, then you should just set up the QuietZoneWidth property to zero (in order to rid of the left and right margins) and after that setting, the following barcode will be generated.
The output barcode image fitting the desired area. No left & right quiet zones are specified.
Finally, keep in mind too that in some cases of high precision barcode generation, increasing the DPI property may be required.
Download Barcode Professional for Reporting Services
More Information about Neodynamic Barcode Professional for Reporting Services
.NET Components & Controls
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!