Reporting Services & Excel – Barcode image size is not properly displayed

It seems that “autosize” images rendered in any list control of RS is not properly displayed when exporting the RDL report to Excel *.xls format. AutoSize feature of our Barcode Pro for RS ensures that the generated barcode will not be “cut off”. This is very important when you are using variable length linear barcodes like Code 39, Code 128, GS1-128, etc. because the barcode length will depend on the amount of characters in the value to encode. For other barcodes like UPC-A/E or EAN-13/ISBN that is not a problem at all because these standards encode fixed length values and the final barcode size can be calculated from the beginning.

Now, back to the Excel “image autosize” issue, there is a workaround which can be applied to avoid this. It involves you disable AutoSize feature on our product and just specify a fixed size for it through Width & Height properties. The only thing to be aware is that for variable length barcodes, you must specify the greatest size which will depend on your data source field which will be encoded into the barcodes.

Let’s apply the workaround to the sample we provide in the “Getting Started – First Steps with Barcode Professional for SQL Reporting Services” In this guide there’s a sample report listing barcodes for the products of AdventureWorks sample DB available in SQL Server 2008

For “Using Barcode DLL Component” report sample, there is the following VB function which is in the Code section of the RDL report:


Public Function GetBarcode(ByVal valueToEncode As String) As Byte()
'Set the value to encode
objBarcode.Code = valueToEncode
'Set the Code 128 Barcode Symbology
objBarcode.Symbology = _
Neodynamic.ReportingServices.Symbology.Code128
'Set the Bar's height to 0.5 in
objBarcode.BarHeight = 0.5F
'Enable AutoSize
objBarcode.AutoSize = True

'Generate the barcode image
Return objBarcode.GetBarcodeImagePng()
End Function

In that function, the AutoSize feature is enabled. If you run the RDL report and export it to Excel you get this:

Image auto-size issue when exporting Reporting Services RDL report to Excel

Notice that the barcodes on the Excel file are being “scaled”. The fact is that the barcode image generated by our product is correct (see the “Original size” info) but is scaled down by Excel without apparent reason (In reality, it seems that Excel is honoring the Height of the “table cell” row and scales the barcode image to fit in).

Let’s change some settings on the GetBarcode function by disabling the AutoSize feature and specifying a fixed image size which will contain the rendered barcode.


Public Function GetBarcode(ByVal valueToEncode As String) As Byte()
'Set the value to encode
objBarcode.Code = valueToEncode
'Set the Code 128 Barcode Symbology
objBarcode.Symbology = _
Neodynamic.ReportingServices.Symbology.Code128
'Set the Bar's height to 0.5 in
objBarcode.BarHeight = 0.5F
'Specify fixed size
objBarcode.AutoSize = False
objBarcode.Width = 1F
objBarcode.Height = 0.75F

'Generate the barcode image
Return objBarcode.GetBarcodeImagePng()
End Function

These new settings will generate an image which size is 1in x 0.75in containing a barcode which bar’s height is 0.5in

NOTE: Please notice that the Width & Height properties are for the final image size NOT the barcode bars! The barcode size is determined by a combination of some properties like BarHeight, BarWidth, BarRatio, Code, etc

Other settings must also be done on the Image control which is invoking the GetBarcode() function. Select the Image control and set the Sizing property to FitProportional AS WELL AS the Width & Height properties to the same values you set up in the GetBarcode()function i.e. Width = 1in and Height = 0.75in
Reporting Services Image control settings
That’s it. Now run the report once again and export it to Excel. The barcode images are now displayed correctly without any scaling!
Image size issue solved when exporting a RDL report to Excel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: