Create QR-Code!

FAQ: TBarCode in Web Applications

FAQ TBarCode: Delays on the Web Server, Barcode Optimization in Web Applications
 

Authenticity Verification

Delays on the Web Server

When running TBarCode on IIS for Windows behind a firewall, a possible delay of 15-30 seconds may occur when the first page is hit. This is caused by IIS because it is authenticating signed .NET / DLL components.

The solution is to replace all TBarCode DLL files with unsigned versions. These are available on request, please contact the TEC-IT support!

Resolution & Readability

Barcode Optimization in Web Applications

When generating bar codes as image stream, the bars (or spaces) should always be aligned on the pixel grid of the generated bitmap.

Note: Without any scaling images in a browser are always displayed in 96 dpi. A thin bar having 1 pixel is normally 1/96 inch wide.

Principally, you shouldn't have any problems printing 96 dpi image on a laser printer with 600-1200 dpi. There are some printing tolerance which may occur while converting 96 dpi to 600/1200 dpi but they are minimal.

In ASP the CountModules, XRows, XCols functions can be used for adjustments. Look at the ASP and PHP samples delivered within the setup. For ASP.NET refer to the sample code below.

It might eventually be more complex to adjust the barcode to a specific size or to adjust the printing resolution to 300 dpi or lower. In this case, you should adjust the barcode module width to the dot-width of the printer.

See section A.4 in the Barcode Reference for more information. We recommend reading the whole Appendix A starting with page 83.

TBarCode .NET

Improve Barcode Quality for Label Printers in ASP.NET

If you print barcodes from within the browser on thermal label printers, you often encounter quality problems. The bars are not equal in width and not adapted to output resolution. In order to avoid bar width aberrations you have to find a full match of Pixels across 96 dpi browser and 203 dpi printer resolution. For linear bar codes the solution is as follows:

  • Bitmap creation: Create the bar code bitmap with 203 dpi and optimized module width (2 or 3 Pixels). Make the whole bitmap exactly 3 or 4 inches wide (= 3 * 203 Pixels or 4 * 203 Pixels) by adding white space as required.
  • Bitmap scaling: Display the bar code image in the browser with a width of exactly 3 or 4 inches (= 3 * 203 Pixels or 4 * 203 Pixels) depending on what you have selected during bitmap creation.
  • This will create a pixel aligned bar code to a 203 dpi raster and good readability.

The following ASP.NET C# code shows how to implement this optimization with TBarCode .NET.

 double dpi = 203; // printer resolution (8 lines/mm)
 int numberOfPixels = 3; // number of pixels for 1 module (= 0.375 mm)
 double moduleWidth = numberOfPixels * 25.4 / dpi; // module width in mm
 
 BCControl.Barcode.Dpi = dpi; // 1 bitmap pixel  = 1 module
 BCControl.Barcode.SizeMode = TECIT.TBarCode.SizeMode.CustomModuleWidth;
 BCControl.Barcode.ModuleWidth = (float) (moduleWidth + 0.001);
 BCControl.Barcode.AdjustModuleWidthToPixelRaster = true;
 
 BCControl.Width = new Unit(96 * 4, UnitType.Pixel); // always a multiple of 96 !!!
When printing the barcode make sure that you have browser scaling disabled (or set to 100%). Also make sure that image dithering or halftone is disabled in the printer driver.

Read permissions

ASP: Library Not Registered

"Server object error 'ASP 0177 : 8002801d' Server.CreateObject Failed (..) - Library not registered"

If you get this error message, you need to change the read permissions of IUSR_MACHINE user account for the type library entry in the registry. Please follow the steps below:

  • Start "regedit" or "RegEdt32.exe"
  • Select HKEY_CLASSES_ROOT
  • TBarCode OCX V8: Search for Type Lib UUID {07EC89D3-07F6-4B94-8A6A-C2347DB5C9EC}.
  • TBarCode OCX V9: Search for Type Lib UUID {E06A2F00-D769-46FE-B2D6-E795C0CEE76E}.
  • TBarCode OCX V10: Search for Type Lib UUID {132760F3-28BE-4E8A-B12B-12810EAA1EA3}.
  • Right click on the registry entry and select "Permissions" from the drop down menu. Alternatively, you can also go to Edit -> Permission.
  • On the next dialog, set read permissions of IUSR_MachineName or EveryOne account.

PDF-417

How can I generate a pixel-optimized PDF417 in VB ASP.NET?

Insert this code into the Page_Load event

  Me.BarcodeControl1.Barcode.BarcodeType = BarcodeType.Pdf417
  Me.BarcodeControl1.Barcode.Data = data

  ' TBarCode V7, V8:
  Dim horizModules As Integer
  Dim verticRows As Integer

  horizModules = Me.BarcodeControl1.Barcode.CalculateXColumnsOf2DBarcode()
  verticRows = Me.BarcodeControl1.Barcode.CalculateNumberOfRows()

  Me.BarcodeControl1.Barcode.SizeMode =  SizeMode.FitToBoundingRectangle
  ' for the dpi use at least 3 times the screen res (or >= 300 dpi) 
  Me.BarcodeControl1.Barcode.Dpi = 96 * 3
  Me.BarcodeControl1.Width = New Unit(horizModules)
  ' for the height use a multiplier of 3 - 5  
  Me.BarcodeControl1.Height = New Unit(verticRows * 5)

End Sub
In TBarCode V9 you can use the new function BCGetOptimalBitmapSize()

Web Farms

Using TBarCode ASP.NET in Web Farms (IIS 7.0)

If you use TBarCode ASP.NET Web Control in a Web Farm you may encounter the following exception:

Exception Type: System.ApplicationException
Message: The requested image is no longer cached.

The TBarCode .NET Web Control uses the HttpContext.Cache object to store the generated barcode image. Since http requests are load balanced within a web farm it can occur that a specific Web Control receives a request for an image, which has been generated on a different application server (and therefore is not available in its local cache).

To overcome this problem you could

  • Synchronize the HttpContext.Cache object on all servers in the web farm (="distributed caches"). This could be done with extra programming or additional third party software.
  • or simply use Client Affinity in IIS 7.0 (recommended)

Having client affinity enabled all requests are tagged with a cookie so that subsequent requests (from the same client) are routed to the same server in the web farm.

See Application Request Routing (Step 3 – Configure client affinity)

Application Request Routing provides a client affinity feature that maps a client to a content server behind Application Request Routing for the duration of a client session. When this feature is enabled, the load balancing algorithm is applied only for the very first request from the client.

TBarCode .NET

How can I Stream a Barcode Image to the Browser (Client)?

With TBarCode it is possible to stream a barcode image (e.g. based on GET or POST parameters) back to the client.

You can take a look on our online barcode generator, where we do this exactly.

This URL streams a barcode image (Data Matrix with the word "TBarCode" encoded) back to the browser: http://barcode.tec-it.com/barcode.ashx

Please use this code snippet as starting point:

 // first adjust the barcode properties of the myBarcode object (class Barcode)
 // then calculate the width and height of the code in Pixels (sample available on request)
 // then write the barcode image as stream to the browser as follows
 
 Bitmap image = myBarcode.DrawBitmap(width, height);
 image.SetResolution(dpi, dpi);

 Response.Clear();
 Response.ContentType = "image/gif";

 image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

 HttpContext.Current.ApplicationInstance.CompleteRequest();
 image.Dispose();

© TEC-IT Datenverarbeitung GmbH, Austria  |  Site Map  |  RSS  |  Imprint  |  Legal Conditions and Privacy  |  Contact