How to use Barcode Professional in Visual Studio Local Report (RDLC) - Windows Forms Invoice Maker Sample with PDF & Excel support
Product Barcode Professional for Reporting Services
Published 04/27/2007
Updated 04/27/2007
Requirements
Neodynamic Barcode Professional 2.0 for Reporting Services or greater
Microsoft .NET Framework 2.0 or greater
Microsoft Visual Studio 2005 or greater
Microsoft Visual Studio 2005 ReportViewer control
Microsoft Visual Basic .NET Express or Visual C# Express with ReportViewer add-in installed
Due to its flexible design, Barcode Professional allows you to easily add barcode images in RDLC (Report Definition Language Client-side processing) reports. You can use all Barcode Symbologies - Linear & 2D - built-in Barcode Professional.
In the following sample we'll extend an application sample called Invoice Maker that is available at http://www.gotreportviewer.com/
From the Invoice Maker's author:
"Invoice Maker demo allows the user to enter data in a form and prepare an invoice. The invoice can then be printed, or exported to PDF or Excel. Almost no coding is needed, other than a couple of simple classes that have some public properties and nothing else."
In this sample we'll extend this application by including barcode images into the invoice report generated by Barcode Professional.
Follow up these steps
- Enter at http://www.gotreportviewer.com/ and download the Invoice Maker Sample (http://www.gotreportviewer.com/InvoiceMaker.zip)
- Extract the downloaded InvoiceMaker.zip file and open the solution with Visual Studio 2005
- Ensure to install Barcode Professional for Reporting Services.
IMPORTANT: After installing Barcode Professional for Reporting Services you must register it into the Global Assembly Cache (GAC). The assembly to register is located in [BarcodeInstallDir]\bin\For SSRS 2005\Neodynamic.ReportingServices.Barcode.dll
- The idea is to add two kind of barcode images onto the Report1.rdlc report file. One barcode image will be a PDF417 barcode image (PDF417 is a well known 2D barcode standard) encoding all customer information and one Code 128 barcode image for each product in the Invoice's detail. Follow these steps:
- Open the Report1.rdlc report at design-time.
- Add a report reference to the Barcode Professional assembly (Neodynamic.ReportingServices.Barcode.dll) going to Report > Report properties…. Add the reference as is shown in the following figure:
We'll need to create an instance of Barcode Professional to use it then in a custom function. To do this, add a new entry in the Classes grid as is shown in the following figure. Note that the instance will be named objBarcode and that the full reference to the class is Neodynamic.ReportingServices.Barcode
- In order to get the barcode images, we need to create VB.NET functions which will be invoked to get the appropriate barcode images by using the Barcode Professional instance created in the previous step. In the Code tab write the following code:
IMPORTANT: If you are using Barcode Professional 3.0 or greater, then modify the line objBarcode.BarHeight = 10 in the function below to objBarcode.BarHeight = 0.1 because in those new versions all barcode-related dimensions are measured in inches instead of pixel!
Public Function GetBarcodeCode128(ByVal code As String) As Byte()
'Set the value to encode
objBarcode.Code = code
'Set the Code 128 Barcode Symbology
objBarcode.Symbology = Neodynamic.ReportingServices.Symbology.Code128
'Set the Bar's height to 10 px
objBarcode.BarHeight = 10
'No Quiet Zone
objBarcode.QuietZoneWidth = 0
'No Text on image
objBarcode.DisplayCode = False
'Generate the barcode image
Return objBarcode.GetBarcodeImagePng()
End Function
IMPORTANT: If you are using Barcode Professional 3.0 or greater, then modify the line objBarcode.BarWidth = 1 in the function below to objBarcode.BarWidth = 0.01 because in those new versions all barcode-related dimensions are measured in inches instead of pixel!
Public Function GetBarcodePdf417(ByVal code As String) As Byte()
'Set the value to encode
objBarcode.Code = code
'Set the PDF417 Barcode Symbology
objBarcode.Symbology = Neodynamic.ReportingServices.Symbology.Pdf417
'Bar's height = BarWidth * BarRatio
objBarcode.BarRatio = 4
objBarcode.BarWidth = 1
'No Quiet Zone
objBarcode.QuietZoneWidth = 0
'Generate the barcode image
Return objBarcode.GetBarcodeImagePng()
End Function
NOTE: In the previous functions we're returning barcode images in PNG format (objBarcode.GetBarcodeImagePng). You can return other image format of the generated barcode using the other GetBarcodeImageXYZ() methods available. (For further info, please refer to Class Reference in the product help)
These VB.NET functions require a code parameter. This value will be specified with some fields of the report’s Data Source. And as you can see in these functions you can set any property of Barcode Professional.
Click OK to close the dialog box.
- Now we'll modify the Report1.rdlc layout. Open the report at design time and drag & drop two Image controls onto the report as is shown in the following figure. Note: We've changed the Customer rectangle containing customer info, adding two separated rectangles inside it in order to keep the barcode image and customer info together. (Please take a look at the downloadable file at the end of this guide). This useful Microsoft whitepaper can help you when designing Reporting Services Reports - SQL Server 2005: Report Design Best Practices and Guidelines
The Image control that will hold the barcode image representing all Customer information (the top one) has to have its Source property set to Database, the Sizing property to AutoSize, the MIMEType property to a image/[format] that matches with the GetBarcodeImage[format] method used in the custom function, and the Value property to the following expression:
=Code.GetBarcodePdf417(Fields!Name.Value & Chr(13) & Fields!Address.Value & Chr(13) & Fields!City.Value & Chr(13) & Fields!State.Value & Chr(13) & Fields!Zip.Value)
The Image control that will hold the barcode image representing each product in the invoice's detail has to have its Source property set to Database, the Sizing property to AutoSize, the MIMEType property to a image/[format] that matches with the GetBarcodeImage[format] method used in the custom function, and the Value property to the following expression:
=Code.GetBarcodeCode128(Fields!Product.Value)
- The last thing to do is to add a line of code in the Form_Load event procedure in the Windows Forms that will show the Invoice reports using a ReportViewer control. So, go to it and add the following line:
• For Barcode Professional 2.0:
Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Neodynamic.ReportingServices.Barcode, Version=2.0.2000.0, Culture=neutral, PublicKeyToken=c6b33c3093a0d4cd")
• For Barcode Professional 3.0:
Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Neodynamic.ReportingServices.Barcode, Version=3.0.2000.0, Culture=neutral, PublicKeyToken=c6b33c3093a0d4cd")
• For Barcode Professional 4.0:
Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Neodynamic.ReportingServices.Barcode, Version=4.0.2000.0, Culture=neutral, PublicKeyToken=c6b33c3093a0d4cd")
Ensure that you've registered or installed the Barcode Professional for SSRS 2005 assembly into the Global Assembly Cache (GAC)
- That's it. Run the app. You'll get something like the following:
Barcode Professional supports PDF & Excel exportation. So, if you do that onto the previous form you'll get your Invoice report with barcode images in PDF and Excel formats as well.
PDF Support
Excel Support
- Deployment
To deploy your project on a client machine, just ensure that the Barcode Professional for Reporting Services is installed or registered in the client's Global Assembly Cache (GAC). For further details, please refer to Deployment topic in the product help.
- Sample Files Download
Here is the VB.NET version of this sample. Please, download the zip file. After extract it you'll find all necessary to reproduce this step by step guide. InvoiceMakerWithBarcode.zip
Remember to download and install Barcode Professional for Reporting Services in order to reproduce this sample demo.