Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barcodes printing with irregular lines

A client asked me to build an inventory solution for them where they'd print barcode labels for all office equipment to keep track of them in various ways.

They gave me a Citizen CL-S621 printer (203x203 dpi resolution) to use for testing and after (the nightmare that was) configuring its drivers to print and fitting everything to the nonstandard labels they gave me to test, the biggest problem I'm still running into is that the printer is having trouble printing some bars in a straight line and instead prints them in dashed/dotted forms.

The C# Code below shows the basics of how I build the barcodes using this library :

public void CreateTheBarcode(string StringToEncode)
{
    Barcode b = new Barcode();
    b.LabelFont = new Font("Sample Bar Code Font", 24, FontStyle.Bold);
    b.IncludeLabel = true;
    b.Encode(BarcodeLib.TYPE.CODE128, StringToEncode, Color.Black, Color.White, 730, 140);
    b.SaveImage(@"C:\temp\Barcodes\"+StringToEncode+".png",SaveTypes.PNG);
    Print(@"C:\temp\Barcodes\"+StringToEncode+".png");
}

public static void Print(string FilePath)
{
    Process printJob = new Process();
    printJob.StartInfo.FileName = FilePath;
    printJob.StartInfo.UseShellExecute = true;
    printJob.StartInfo.Verb = "printto";
    printJob.StartInfo.CreateNoWindow = false;
    printJob.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
    printJob.StartInfo.Arguments = "\"" + "Citizen CL-S621" + "\"";
    printJob.StartInfo.WorkingDirectory = Path.GetDirectoryName(FilePath);
    printJob.Start();
}

The hardcoded width and height are the best approximation I found of a good image size the printer would accept and accurately print onto the labels since I had to measure their size by ruler and between printer offsets and eye-measurement accuracy issues getting a size that worked proved troublesome.

In any case, I generated some barcodes and the images are crisp, clear and seem pretty good:

All images are to scale. I joined them into a single file for ease. I'm not sure why some barcodes are narrower than others

The lines are straight and clearly defined, the text is sharp, everything seems fine; but when I go to print them I get:

They print out of order for some reason, I suspect the printer has some sort of optimizer that arranges them so

Some of the bars print straight and clear while some have irregular edges and some are just irregular dot/slash/curved patterns. The text in all of them suffers the same issue. I have tried different font sizes and supposedly barcode-friendly fonts and the issue persists. The problem persists if I remove the text labels.

It strikes me as an image rasterization issue but I am not fully sure, nor do I know how to fix that.

I'm not yet sure if a scanner can read these or not, I receive one tomorrow, but any tips on what I may be doing wrong would be appreciated.

like image 814
ConnorU Avatar asked Jan 05 '23 14:01

ConnorU


2 Answers

These printer settings should help:

Select the printer in Device and Printers > Printing Preferences > Graphics

Set Dithering to None

like image 88
Mehravish Temkar Avatar answered Jan 20 '23 06:01

Mehravish Temkar


The printer is antialiasing your images. This is an endemic problem with barcode fonts. You have to either set your printer to not antialias (try Settings/Printer/Printing Preferences/Color Mode/Monochrome) or you have to set the image DPI to be identical to the printer DPI (typically 300 DPI).

If your printer renders to a rectangle and not to a DPI, you have to size your image so the image pixels are an integer multiple of the printer pixels of the same rectangle.

It's difficult to propose a solution to your problem because you have too many moving parts; you start with a font that goes to an image that goes to a file that goes to a shell command that goes to an application you haven't told us about that goes to a printer. Any one of those steps could anti-alias your image.

My suggestion is to remove these intermediate parts. What's calling CreateTheBarcode? An application you wrote? Try having that application print to the printer directly using .NET System.Drawing.Printing.PrintDocument. You can't do that and have to use the mystery application UseShellExecute calls? Study that application, maybe there is some way you can send printer commands instead of going through all that font to image to file rigamarole; many label printers have ways to output text like “test 123” directly as barcodes.

Edit: Maybe what you are attempting is flat-out impossible. What are the dimensions of the label you are printing to? Your “More numbers” example is over 500 px across and your printer is only 200 DPI. If the labels are narrower than 500/200 ≅ 2.5 inches there is no way the bars will fit even if you print at 203 DPI.

like image 21
Dour High Arch Avatar answered Jan 20 '23 08:01

Dour High Arch