Now, you can deliver barcode images in your Crystal Reports web reports using Barcode Professional. Following this FAQ you can export your report to PDF format maintaining the barcode images into it!
Neodynamic Barcode Professional 2.0 (or greater) for ASP.NET (WebControl)
Crystal Reports for .NET (any version)
Microsoft .NET Framework (any version)
Microsoft Visual Studio .NET (any version)
Microsoft SQL Server Northwind Database
In the following sample we're going to create an ASP.NET Web Application which includes a CR reports and which shows barcode images into that report using Barcode Professional.
In this sample, we're going to use the Microsoft's Northwind database shipped with SQL Server. If you don't have SQL Server, you could use MSDE and get the Northwind database sample from Microsoft Office CD too.
Follow these steps:
'Connection Info
'CHANGE the values as you need
Dim scnn As String = "server=(local);database=NorthwindCS;trusted_connection=true"
Dim cnn As New SqlClient.SqlConnection(scnn)
'Get Orders info
Dim sqlOrders As String = "SELECT dbo.Orders.OrderID, dbo.Customers.CompanyName, dbo.Customers.Address, dbo.Customers.City, dbo.Customers.PostalCode, dbo.Customers.Country, dbo.Orders.OrderDate, dbo.Orders.RequiredDate, dbo.Orders.ShippedDate, dbo.Orders.ShipVia, dbo.Orders.Freight, dbo.Products.ProductID, dbo.Products.ProductName, dbo.[Order Details].UnitPrice, dbo.[Order Details].Quantity, dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity AS TotalLine, dbo.Customers.Region FROM dbo.Customers INNER JOIN dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID"
Dim cmd As New SqlClient.SqlCommand(sqlOrders, cnn)
'Create DataSet for Orders
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
'Create the XML Schema for Orders
'Be sure you give write permission to ASPNET account to Temp folder
ds.WriteXmlSchema("C:\temp\orders.xsd")
//Connection Info
//CHANGE the values as you need
string scnn = "server=(local);database=NorthwindCS;trusted_connection=true";
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(scnn);
//Get Orders info
string sqlOrders = "SELECT dbo.Orders.OrderID, dbo.Customers.CompanyName, dbo.Customers.Address, dbo.Customers.City, dbo.Customers.PostalCode, dbo.Customers.Country, dbo.Orders.OrderDate, dbo.Orders.RequiredDate, dbo.Orders.ShippedDate, dbo.Orders.ShipVia, dbo.Orders.Freight, dbo.Products.ProductID, dbo.Products.ProductName, dbo.[Order Details].UnitPrice, dbo.[Order Details].Quantity, dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity AS TotalLine, dbo.Customers.Region FROM dbo.Customers INNER JOIN dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlOrders, cnn);
//Create DataSet for Orders
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
//Create the XML Schema for Orders
//Be sure you give write permission to ASPNET account to Temp folder
ds.WriteXmlSchema("C:\\temp\\orders.xsd");
Imports Neodynamic.WebControls.BarcodeProfessional
using Neodynamic.WenControls.BarcodeProfessional;
'Connection Info
'CHANGE the values as you need
Dim scnn As String = "server=(local);database=NorthwindCS;trusted_connection=true"
Dim cnn As New SqlClient.SqlConnection(scnn)
'Get Orders info
'Only Country = USA
Dim sqlOrders As String = "SELECT dbo.Orders.OrderID, dbo.Customers.CompanyName, dbo.Customers.Address, dbo.Customers.City, dbo.Customers.PostalCode, dbo.Customers.Country, dbo.Orders.OrderDate, dbo.Orders.RequiredDate, dbo.Orders.ShippedDate, dbo.Orders.ShipVia, dbo.Orders.Freight, dbo.Products.ProductID, dbo.Products.ProductName, dbo.[Order Details].UnitPrice, dbo.[Order Details].Quantity, dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity AS TotalLine, dbo.Customers.Region FROM dbo.Customers INNER JOIN dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID WHERE dbo.Customers.Country = 'USA'"
Dim cmd As New SqlClient.SqlCommand(sqlOrders, cnn)
'Create DataSet for Orders
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds)
'The DataSet DOES NOT include the BarcodeImage "column"
'or element we've included in the XML Schema file.
'So, create the BarcodeImage column
'WARNING: you must name it as you did in the XML Schema
Dim dc As DataColumn = New DataColumn("BarcodeImage", GetType(Byte()))
'Add the BarcodeImage column to the DataTable
ds.Tables(0).Columns.Add(dc)
'Create a BarcodeProfessional object to fill
'the BarcodeImage column
Dim bc As BarcodeProfessional = New BarcodeProfessional
'We are going to use Code 128 Barcode Symbology
'but you could use other
bc.Symbology = Symbology.Code128
'Set some properties of Barcode Professional. Play with them.
bc.BarHeight = 0.5F 'Set System.Web.UI.WebControls.Unit.Pixel(50) if you use Barcode Professional 2.X
bc.Text = ""
bc.QuietZoneWidth = 0 'Set System.Web.UI.WebControls.Unit.Pixel(0) if you use Barcode Professional 2.X
bc.DisplayCode = False
'Now, generate and fill barcode images
For Each dr As DataRow In ds.Tables(0).Rows
'We're going to encode the OrderID column
bc.Code = CStr(dr("OrderID"))
dr("BarcodeImage") = bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
Next
'Create a Orders report object
'and set its data source with the DataSet
Dim report As New Orders
report.SetDataSource(ds)
'Export report to PDF format
'NOTE: Give write permission to ASPNET account to Temp folder
Dim DiskOptions As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
DiskOptions.DiskFileName = "C:\TEMP\OrdersWithBarcodeImages.pdf"
report.ExportOptions.DestinationOptions = DiskOptions
report.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
report.ExportOptions.ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
report.Export()
'And Show it!
CrystalReportViewer1.ReportSource = report
//Connection Info
//CHANGE the values as you need
string scnn = "server=(local);database=NorthwindCS;trusted_connection=true";
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(scnn);
//Get Orders info
//Only Country = USA
string sqlOrders = "SELECT dbo.Orders.OrderID, dbo.Customers.CompanyName, dbo.Customers.Address, dbo.Customers.City, dbo.Customers.PostalCode, dbo.Customers.Country, dbo.Orders.OrderDate, dbo.Orders.RequiredDate, dbo.Orders.ShippedDate, dbo.Orders.ShipVia, dbo.Orders.Freight, dbo.Products.ProductID, dbo.Products.ProductName, dbo.[Order Details].UnitPrice, dbo.[Order Details].Quantity, dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity AS TotalLine, dbo.Customers.Region FROM dbo.Customers INNER JOIN dbo.Orders ON dbo.Customers.CustomerID = dbo.Orders.CustomerID INNER JOIN dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order Details].OrderID INNER JOIN dbo.Products ON dbo.[Order Details].ProductID = dbo.Products.ProductID WHERE dbo.Customers.Country = 'USA'";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlOrders, cnn);
//Create DataSet for Orders
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
//The DataSet DOES NOT include the BarcodeImage "column"
//or element we've included in the XML Schema file.
//So, create the BarcodeImage column
//WARNING: you must name it as you did in the XML Schema
System.Data.DataColumn dc = new System.Data.DataColumn("BarcodeImage", typeof(byte[]));
//Add the BarcodeImage column to the DataTable
ds.Tables[0].Columns.Add(dc);
//Create a BarcodeProfessional object to fill
//the BarcodeImage column
BarcodeProfessional bc = new BarcodeProfessional();
//We are going to use Code 128 Barcode Symbology
//but you could use other
bc.Symbology = Symbology.Code128;
//Set some properties of Barcode Professional. Play with them.
bc.BarHeight = 0.5f; //Set System.Web.UI.WebControls.Unit.Pixel(50) if you use Barcode Professional 2.X
bc.Text = "";
bc.QuietZoneWidth = 0; //Set System.Web.UI.WebControls.Unit.Pixel(0) if you use Barcode Professional 2.X
bc.DisplayCode = false;
//Now, generate and fill barcode images
foreach(System.Data.DataRow dr in ds.Tables[0].Rows)
{
//We are going to encode the OrderID column
bc.Code = dr["OrderID"].ToString();
dr["BarcodeImage"] = bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
}
//Create a Orders report object
//and set its data source with the DataSet
Orders report = new Orders();
report.SetDataSource(ds);
//Export report to PDF format
//NOTE: Give write permission to ASPNET account to Temp folder
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
DiskOptions.DiskFileName = "C:\\TEMP\\OrdersWithBarcodeImages.pdf";
report.ExportOptions.DestinationOptions = DiskOptions;
report.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
report.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
report.Export();
//And Show it!
CrystalReportViewer1.ReportSource = report;
Sample Files Download
Here are a VB.NET and C# versions of this sample. Please, download the appropriate zip file. In it you'll find these files:
To reproduce this sample on your own machine, create a new ASP.NET Web Application. Name it as BCWebSampleCRPDF, add to it the downloaded files and review the steps described above.
Download the source code here:
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.