6

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.

cDecker32
  • 813
  • 1
  • 10
  • 20
  • I think you need to provide more details on how you are sending this to a printer. Through an API? Or if your receipt is being viewed in a browser, then the browser will take care of sending the image to the printer when you print. Of course you'd probably want to test this out against the hardware to make sure you aren't exceeding the size of the print area. – AaronLS Mar 13 '12 at 22:23
  • Zebra printers have an incredibly obscure proprietary data format. Trying to convert image formats is one too many, you'll be ahead by just simply using the Windows printer driver. PrintDocument in your code. – Hans Passant Mar 14 '12 at 00:23
  • Is there any way I could convert an XML to a .lbl and see whats actually getting rendered? – cDecker32 Mar 14 '12 at 15:28
  • Ok we're not sending XML files, those were just used to help fill in values. So basically we're just sending a zpl stream to the printer. – cDecker32 Mar 14 '12 at 20:51

1 Answers1

6

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).

Ethan
  • 6,883
  • 3
  • 33
  • 41
  • I actually came here to post that I found this out last night, but you won sir. I finally figured it out by playing around with the numbers that specified the original image files. Now the question is how to reduce an RGB PNG into a bitonal tiff/bitmap in C#. – cDecker32 Mar 16 '12 at 13:13
  • Something I found real quick: `System.Drawing.Bitmap b = new System.Drawing.Bitmap("c:\\test.jpg");` `System.Drawing.Bitmap b0 = CopyToBpp(b,1);` I found that here: http://www.wischik.com/lu/programmer/1bpp.html . – Ethan Mar 16 '12 at 15:48
  • Yea over the course of the day I worked on this and the only issue now is some sort of offset issue. Most likely because I'm converting from a bmp. I just need to figure out what sort of file header this thing is looking for... – cDecker32 Mar 16 '12 at 21:52
  • There shouldn't be any header data. It should just be bits of data for the print engine to render with. So strip any header data off the image before sending it down. – Ethan Mar 18 '12 at 03:47
  • Wow that did it, Thanks a lot! I could have sworn I was doing just that initially, and I wound up with something that didn't look anywhere close to what I actually needed. – cDecker32 Mar 19 '12 at 13:37
  • Fantastic! Glad I could help! I have ran into that problem before with sending down data to the printer. Something you learn after using them for a while. – Ethan Mar 19 '12 at 13:45