FAQ TBarCode in Web Applications
Improve Barcode Quality for Label Printers in ASP.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.