This question already has answers here:
Printing PNG images to a zebra network printer
(6 answers)
Closed 8 years ago.
I'm working on creating a HTML5 canvas based signature/drawing box. Currently we save the canvas on the server as a PNG, but can easily save the base64 string in the database. Now the question is how do we include the signature on the printed receipt.
Currently we use a ^GF field to handle printing images, but the question is what format the PNG file needs to be in for the printer. Can I simply include the Base64 encoded string? Or should I convert it to an ASCII Hex string? Or should I really be converting it into a bitmap first?
I'm not really finding any documentation on whether or not this specific printer handles PNG files, or even how to send them. The only information I've found says to send it as a B64 or Z64 bitmap, but I see references to sending a png everywhere.
The data that is you need to send isn't a PNG. You need to take the image and convert it to black and white and send the data to the printer. For example, if you have an image that is 40x50px you would take the image, and strip out the color information so you would have a total of 2000 bits of data. Then send your ZPL down like ^GFB,250,250,5,{2000 bits of data}.
I got 250 by taking 2000 bits / 8 (bits / byte) to get 250 bytes. I got 5 by dividing 40 by 8. The number of rows will be calculated automatically.
Something that I find useful when dealing with Zebra printers is to think in terms of bits. All graphics are done on a bit level.
Remember that the image you are going to send down will change size depending on the DPI of the printer. A 203 DPI printer will show my example at about .2in x .25in. On a 300 DPI printer it will show at about .13in by .16in. This is because the printer will just place raw data onto the format and the number of px is the number of dots the image will be.
Hope this help!
References:
[1] ZPL Manuel on page 208(^GF page2).
Related
I am trying to implement my own monochrome/black and white filter in C# to scan text documents. My approach is to apply a threshold filter on the captured image. However, I often run into the problem that the varying brightness on the image causes a ''shadowing effect'' on the processed image. Refer to the link below (it is pretty blurry but it should suffice). The image to the far left is the original image. When I apply my threshold filter, I get the same result as the image in the middle; some of the text becomes unreadable because the brightness of the image varies, so some portions become really black or really white. However, with the right filter, you can obtain the processed image to the right where everything looks crystal clear.
https://www.google.dk/search?q=monochrome+image+processing&espv=2&biw=1706&bih=859&source=lnms&tbm=isch&sa=X&ved=0ahUKEwir8vXlhIzPAhUFiywKHeSBC1wQ_AUIBigB#imgrc=4UTzoIpyqTkwrM%3A
I would like to know what the process is to obtain the image to the far right. Another example can be seen in the image below. It shows a sample mobile PDF scanner in use. Scanning the image results in a very nice black and white image, where the text can be easily read and no ''shadowing'' occurs on the image. Does anyone know what this process is or what it is called? It is very often used in mobile PDF scanning applications. Thank you in advance.
EDIT: The filter is called ''Adaptive Thresholding''. You can use the BradleyLocalThresholding class to implement the filter, or you can write it yourself (which is what I did). Please refer to my response to the comment by Yves Daoust down below.
You need two ingredients.
One is "background reconstruction", i.e. retrieving the intensity of the white sheet "under the characters", for instance by morphological opening.
The other is "shading correction", i.e. compensating the unevenness of the background illumination by comparing to the reconstructed background, for instance by subtraction.
This will "flatten" the image, making it perfectly amenable to global thresholding.
A simple method is to convert the image to grayscale and then convert it to B/W using an error diffusion algorithm such as Floyd–Steinberg dithering.
//Please don't close this post due to subjective reasons.
I'm developing a form-filling winform application which generates a PDF file on submitting the information. The PDF file need to contain barcodes encoding some information entered by user. The user prints the PDF file and put signature on it and faxes it back to us. I need suggestions for choosing which barcode symbology to use for this applcation.
The barcode needs to satisfy the following conditions.
1)The barcode need to encode upto 120 characters
Since the barcode need to encode a lot of information, I think 2D Barcode would be better as it can store with much high information density.
2)Only upper case alphabets and numbers need to be encoded
Though most of the 2D barcodes can store more than numbers, there are some 1D barcodes such as code 39 that cannot represent all alphabets.
3)Preferable size of barcode is 1.5 inch height and 8 inch width
This is what is the most challenging requirement. I'm planning to place the barcode below the information such as account id. So it would be good if barcode takes the shape of a rectangle whose information capacity increases with its width. This requirement is suitable for 1D barcodes. Also, since 2D barcodes takes the shape of a square, a lot of space will be wasted on either side of barcode.
4)Error correcting capability
2D barcodes have better error correcting capability. Only some 1D barcodes have error correction with it. This is not an essential requirement.
5)The barcode need to be faxed from one country to another
The barcode is generated on a PDF. The PDF will be printed and then need to be faxed. So, the barcode needs to have high resolution. Otherwise, I fear that the scanner cannot decode data correctly. I'm thinking a resoltion of 200dpi is enough for the barcode image. Is there any problem to fax 2D barcodes as they need to be scanned both horizontally and verically. I have heard like fax have different resolution vertically and horizontally. Does this create any problem when scanning barcodes.
6)Easiness to program in c# to generate barcode
Atlast but not the least, I need to program this barcode generation myselfin c#. So, there should be some free library available for the same. Aspose barcode is a good one. But it is costly.
I have come across the following Barcodes. I have checked the specification of some of these types. But couldn't reach a final decision. I can't turn back once I choose a barcode and start programming.
1D: UPC/EAN/JAN, Code 39, Code 128, Interleaved 2 of 5, Codabar, Code 11, Code 93, NEC 2 of 5, Matrix 2 of 5, Trioptic Code,
Stacked 1D: PDF417, Micro PDF417, Codablock A & F, Composite Codes
2D: Data Matrix, QR Code, Micro QR Code, Aztec Code, Maxicode
I am thinking of using PDF417. Does it have any disadvantages?
I don't know all formats so I can't say which is best.
Some of the 1D barcodes you mention (UPC/EAN) support only a small number of numeric characters. I know Code 128 supports variable length alphanumeric values, so that probably is a good 1D candidate.
Some barcode readers don't support 2D barcodes, this is usually a reason to use 1D.
Of 2D you should see if there is a symbology that does not require the barcode to be a square, because that would limit your maximum size to 1.5 by 1.5 inches.
There are several websites that let you create barcodes as images - perhaps you should just create a PDF containing those and fax them to see what happens.
I don't know of any free libraries to render them with; there are also fonts out there that allow creating 1D barcodes, and you can embed these fonts into your winforms application.
EDIT: 200 dpi on 8x1.5 inches would give you 1600 dots horizontally and 300 dots vertically to work with. A code128 barcode with a bar width of 1 pixel would come out at under 1400 dots.
On the wikipedia page for QR there is an example that takes up to 174 characters that has a size of 57x57 and high error correction. If I'm not mistaking, each dot could be represented by 5x5 pixels in 200dpi.
I am wondering under the .Net, what if the 32BPP true colored PNG is displayed in the old display card? I believe there is no palette inside PNG file.
Anyone knows the internal logic behind this scenario?
Winforms calls RealizePalette() in the paint message handler to select the default Windows halftone palette, the one returned by Graphics.GetHalftonePalette(). The code it uses is very similar to the example shown in that MSDN article. The pixels in the bitmap are mapped to one of the 256 colors in the actual realized palette when it is drawn. The visual result is of course less than stellar, the 256 color mode is in the museum one stop past the floppy disk drive.
I did like to print a barcode using C#. I want the barcode to have a given height and width. I did download a free 3 of 9 barcode font and used
Font barcodeFont = new Font("Free 3 of 9", 17, FontStyle.Regular);
e.Graphics.DrawString("*"+label.Lpn+"*", barcodeFont, Brushes.Black,new RectangleF(166,235,115.16f,61));
to print it. I have two issues with this.
) for some font size barcode is
printed in two line.
) even if I
reduce the font and make it print in
one line. The barcode does not scan
well. I have to swipe it in a
perticular way to make it work.
Is there a better way to print barcode which will scan every time??
There are minimum and maximum widths for the lines and spaces of a 3of9 barcode.
Take a look at this website for more info about these measurements: http://www.adams1.com/39code.html
Take a look here at CodeProject for a decent Barcode generator. This is capable of generating different types of Barcodes including 3 of 9.
Hope this helps,
Best regards,
Tom.
Code 3 of 9 does tend to be quite a wide barcode and the only way you'll really solve your problem is by giving it more space on the page.
An alternative to this would be to either encode your data so it takes up less characters/bars or instead do a database lookup, so 1 = Bananas, 2 = Apples, 3=VeryLongWordThatDoesntFit etc.
Another alternative would be to improve the quality of the barcode scanner. It is true with barcode scanners that the more you spend the better results you get.
Does the barcode font provide recommended point sizes? A free font might not have the hinting required to insure that each bar is an integral number of pixels wide. This might be a problem especially if your printer has an odd DPI. I'm aware of one model of label printer that is 203 DPI, good luck matching your font size to pixels on that printer!
anyone can please tell me the code how to print documents on dot matrix printer in C# windows application.
You can print to dot matrix "graphically", which is built-in in Windows, albeit slower.
But if you only want to print pure text with simple formattings, you need to send escape commands to your dot matrix printer, which is faster than graphical printing. Different printers has different escape commands.
Here are typical escape commands(for epson): http://www.printfil.com/manualen/c5.htm
This might help: https://web.archive.org/web/20051212193242/http://sacpcug.org:80/archives/0306/prc0603.html
What I do in VB6 then was to print to Generic / Text Only printer, you open the PRN or LPT1 as a file handle, then print escape commands on the file handle, all escape commands will be redirected to whatever printer is attached to LPT1 or PRN. You can do the same thing with C#, just open the PRN or LPT1 as a file, then print to it.
To add Generic / Text Only printer, Control Panel > Printers > Add Printer. On manufacturer, select Generic, then on printers, select Generic / Text only.
You can do the same (printing on Generic / Text Only) for Zebra printers which have their own escape commands for printing bar codes, which is faster than letting Windows print to it graphically.
When you print to an inkjet or laser printer, you generally do not use built-in fonts of the printer. You use Windows fonts. What happens is that the printer driver either builds an image of pixels (including the text) and sends it to the printer, or sends commands designed to draw lines, spline curves, and other shapes to the printer, with fonts expressed as lines and splines (outlines).
When you print to an older dot matrix printer, you can do it that way, but it’s slow. Each line of text has to be “built” from pixels, and often the lines of text do not match up with the passes of the print head (especially for fonts much larger or smaller than 12-point).
The old way of using these printers, the way they were intended, was to send the actual ASCII codes of the text to the printer. Send the number 65 (decimal), and you get a capital (upper-case) “A” for instance. The number 49 (decimal) would print the digit “1” while the number 32 would be a blank space, 33 an exclamation point (“!”), and so on. One byte = one character. The dot-matrix printer had its own built-in font, and would look the ASCII code up in its font ROM, and from there determine the exact timings of which print wires would have to strike the page exactly when to produce those letters.
By using ESCape codes, you could specify such effects as pseudo-boldfaced (basically striking the letter twice, with the second copy shifted to the right by only one dot width), double-wide (striking each column of wires twice in a row for each one time that it would normally be struck, thus doubling the width of the letter), underline (striking the bottom print wire throughout regardless of whether the letter shape calls for it at that point or not), and so on.
The printer’s own ROM handled all of these mechanical details about print wires and such. All your program had to supply is the actual ASCII codes of the text (including control codes such as the number 13 [Carriage Return aka CR] to return the print head to the left margin [or, for a bidirectional printer, prepare to print the next line in the reverse order of the previous line], usually followed by the number 10 [Line Feed aka LF] to roll the paper up one line to prepare for printing the next line).
If you wanted to print in fancy fonts that the printer didn’t have, or print graphics, you had to use an ESCape code to set the printer into “graphics mode” in which you basically sent bytes whose bits would specify to fire the individual wires of the printhead under direct program control, rather than looking up character shapes in the printer’s Font ROM. When you print normally from Windows using a printer-specific driver, this is usually what happens.
For daisy-wheel or other fixed-character printers (e.g. IBM Selectric type-ball mechanisms), the ASCII code would spin the wheel or ball to the proper position and then strike the ribbon and thus print the letter on the page, or send the right hammer up to hit the ribbon and thus the page (TeleType or old typewriter mechanism). It was not possible to do pixel graphics with these except by printing repeated periods and micro-advancing the print head and paper the width/height of a period instead of a character / row of text, respectively (which would generally wear out the period character of the daisy-wheel or ball really quickly, so many of them had metal-reinforced periods for that very reason).
How is this different from printing on inkjet or laser printer?
MSDN: Printing Overview
Preview and Print from Your Windows Forms App with the .NET Printing Namespace
Whilst it wasn't in C#, I have written Access reports that used the native fonts of an Epson printer. It was a few year ago - using Windows XP - but when the printer was selected as the default it was possible to choose the "native" fonts of the printer via the font chooser.
It was pretty neat - I could use any font I liked for the headings, which were slow to print. Then I could select the native printer font for the detail rows, which were fast. Doing it that way I had to be careful that all the "native" font detail stauff had exactly the same vertical alignment, otherwise it became slow again.