Using NuGet to install ConnectCode Barcode Software and Fonts DLL for .Net


What is NuGet?

NuGet is a package manager for the Microsoft development platform that aims to make the process of incorporating third party libraries into your projects as simple as possible. NuGet can be used from the command line or automated via scripts and is bundled from Visual Studio 2012 onwards. As Nuget is free and open source, it has evolved into a large ecosystem of tools and services since its introduction.

Why do I need a DLL and barcode fonts to generate barcodes?

The use of fonts is well known in the auto-id industry for creating barcodes of the highest quality that meet the strictest industry requirements. When a font is printed, it rasters to the resolution of the printer and will not be limited to the Dots per Inch (DPI) of the devices' screens. We thus recommend the use of fonts to generate barcodes.

The DLL, on the other hand, helps you translate input data to barcode output characters that correspond to the font, generate check digits and ensure that the encoded data complies with industry specifications.

Can I use fonts in an ASP.Net (Active Server Pages) or other web project to create barcodes?

Yes. The versatility of a font makes it a popular solution for integrating with existing enterprise projects such as an ASP.Net (or Javascript) project for generating barcodes. The Web Open Fonts Format is the World Wide Web Consortium (W3C) compliant way of transmitting a font to an internet browser. Once a font is transmitted to the browsers ,it can be deployed to generate barcodes.

ConnectCode Barcode Software and Fonts package provides barcode fonts in Web Open Fonts Format (WOFF), True Type, Open Type and Embedded Open Type (eot) formats. This allows barcodes to be generated on all modern browsers that supports WOFF and all legacy browsers that only supports True Type, Open Type or Embedded Open Type (eot).

How do I install ConnectCode Barcode Software and Fonts DLL using NuGet Package Manager?

To install ConnectCode Barcode for .Net using Fonts, run the following command in the Package Manager Console

PM> Install-Package ConnectCodeBarcodeFontsLibrary.dll -Version 1.0.x

.NET Framework Versions of the DLL available in nuget.org

  • .NET 2.0
    This DLL is also available in the "Resource\Net DLL Integration Samples\DLL" subfolder of ConnectCode Barcode Fonts package.
  • .NET 4.0
    This DLL is also available in the "Resource\Net DLL Integration Samples\.Net4.0" subfolder of ConnectCode Barcode Fonts package.
  • Portable class library for Windows Store apps and .NET 4.5

Tutorial on using Nuget to install ConnectCode Barcode DLL in an ASP.Net Project


Prerequisite 1. Launch Visual Studio and go to File->New Project.

2. Select an ASP.Net Project and click on the OK button. You can choose to create from either a Visual C# or Visual Basic template.



3. In the next screen, select the "Web Forms" template, uncheck "Host in the Cloud" (or check it if you have Azure) and click on the OK button.

4. A complete ASP.Net project will be generated for you. Next, go to Tools->NuGet Package Manager->Manage Nuget Packages for Solution.



5. Search nuget.org for "ConnectCode Barcode Fonts" and wait for the results.

6. Select the "ConnectCode Barcode Fonts Library for .Net" package and click on the install button. A dialog will be displayed asking you whether you want to install the package into your project. Click on the OK button.

7. The DLL will be downloaded from nuget.org and installed into your solution. Click on the Close button to exit from the Manage Nuget Packages dialog.

8. Expand the References section of your WebApplication in the Solution Explorer. Check that a reference for ConnectCodeBarcodeFonts.DLL has been added.



9. Next we will add the fonts from the ConnectCode Barcode Software and Fonts package. Right click on the fonts folder in Solution Explorer. Select "Add->Existing Item..." and navigate to the Resource\webfonts\javascript\code39\fonts subdirectory of ConnectCode Barcode Software and Fonts package. Select the following files in the fonts directory. ConnectCode Barcode Software and Fonts package is by default installed in the "C:\Program Files (x86)\ConnectCodeTrial" folder.

ConnectCode39_S3_Trial.eot
ConnectCode39_S3_Trial.otf
ConnectCode39_S3_Trial.woff

10. Once the fonts are added we are ready to generate barcodes in an ASP page. Expand Default.aspx and double click on Default.aspx.cs. Add the following lines of code into the Page_Load function. The following lines of code generates a Code 39 barcode with a check digit using the input data "12345678" and apply the Code 39 barcode fonts to the output.


BarcodeFonts enc = new BarcodeFonts();
enc.BarcodeType = BarcodeFonts.BarcodeEnum.Code39;
enc.CheckDigit = BarcodeFonts.YesNoEnum.Yes;
enc.Data = "12345678";
enc.encode();            
barcode.InnerText = enc.EncodedData;
barcode.Attributes.Add("style", "font-weight: normal; font-style:normal; 
line-height:normal; font-family: 'CCode39_S3_Trial', 
sans-serif; font-size: 32px");
barcode_text.InnerText = enc.HumanText;

// Remeber to add "using Net.ConnectCode.Barcode;" to the top of the class.


11. Next, double click on Default.aspx. Immediately after the following line:


<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" 
runat="server">


Add the following tags:


  <STYLE TYPE="text/css" media="screen,print">
  @font-face {
    font-family: CCode39_S3_Trial;
    src: url("fonts/ConnectCode39_S3_Trial.eot");
    src: local("CCode39_S3_Trial"), 
	 url("fonts/ConnectCode39_S3_Trial.otf") format("opentype"), 
         url("fonts/ConnectCode39_S3_Trial.woff") format("woff");
  }

  #barcode {font-weight: normal; font-style: normal; line-height:normal; 
            font-family: 'CCode39_S3_Trial', sans-serif; font-size: 32px}

  </STYLE>
  <br /><br />Output : <br /><br />
  <div style="width:5in;text-align:center">
      <div id="barcode" runat ="server">12345678</div>
      <div id="barcode_text" runat ="server"></div>
  </div>


The @font-face tag is a CSS font selector for defining fonts used in the elements of a web page. Basically, we are defining Code 39 barcode fonts to be used in the "<div id=barcode>" element.

12. We are now ready to run the project. Click on the Run Internet Explorer button or Debug->Start Debugging in Visual Studio. You should see the following web page:



The barcode above contains horizontal trial markings that should not affect scanning. These markings will not appear in the registered version of ConnectCode Barcode Software and Fonts. The DLL in nuget.org together with the fonts in the ConnectCode Barcode Software and Fonts package can be deployed to an enterprise project with a Distribution License.