DevLife: Converting BMP to PCL

Signature Capture.

You do it every time you buy something with your card at the supermarket.  You might even do it when you go to the dentist.  You sign your name, maybe even press a few buttons, and the signature gets saved and converted into a bitmap or some similar kind of format.  Where I live, I need to take it further and convert the bitmap into a PCL file so that our IBM i (formerly known as the AS/400,  or iSeries, or Series i, or whatever the IBM marketing folks have planned in the future as the name of the year to call this midrange beast) can duly attach this digital copy of our John Hancock to an invoice, perhaps, or even an inner-enterprise document.  Whatever, like, whatever!! Guuyeeee!

So doing this kind of coding is tedious, dry, and beastly geeky.  I feel like an assembly coder for gawdsake!  Ouch, my inner geek can only take so much.

So here’s how you do it.  As you can tell, this is procrastination at its finest.  I’d rather type about it than actually DO IT.

I need a one-layer 8-bit bitmap.  Not compressed.
Then I call ImageMagick to convert that sucker to a PCL format.

Easy, right?  WRONG, reader, WRONG!!!!

The PCL that comes up is all messed up.  It needs cleaning.  Like a toilet needs cleaning.  If you don’t clean it, well, you know.
So I take this ugly PCL and try to turn it into a beauty queen,  one fracking BYTE at a time.

ImageMagick places 0x20’s all over the place, when I need nulls (0x00).
ImageMagick has row blocks of 250 bytes.  I need them to be 32.

I also need to somewhat compress this file so it is smaller – that means getting rid of the extra rows in there I do not need — but this also means I cannot get rid of the good bytes — we need to make sure we create a file that is legible – it is a signature capture application, dummy, not a picture of some horse manure.

There is a whole bunch of other stuff in there that pisses me off that we will need to basically ignore.

I am not going to show you the code yet.  Mostly, because I haven’t done it yet. I will be doing it, however, in C# this time. Why? Because I have to, that’s why, and that’s the way it is.  Maybe I’ll post source code for you in upcoming posts on the FIST if anything just to keep you readers on top of your geek edge.  For example, you’ll be able to say, proudly, at the next Comic Con that you were able to figure out how to convert an uncompressed one-layer bitmap to a Printer Control Language file using file streams, binary reader and writers, byte arrays, block copy methods and bitwise comparisons using the C# language.  Fuck.  Yes.

Here is a pic of the BMP, its PCL conversion from ImageMagick, and the resulting file I need in the end.  Show THAT to your BFF!


Author: JFinger

Seeking everlasting equilibrium between left and right brain activity, JFinger is a software engineer and (semi)retired classically trained musician who would come out of retirement only if put up in a nice beachhouse in the tropics with a servant offering unlimited margaritas. Meanwhile, he will continue brewing hand-crafted organic beers, a craft he has enjoyed since the late 1980s. He finds politics interesting, as well as finance, economics, sports and the funnies. He likes to read the newspaper, or at least he did before they closed them all down. Having been brought up in the newspaper business (son of a Hearst Corporation-owned newspaper reporter), JFinger is always on the lookout for some interesting and worthy story to share on the FIST.

Share This Post On


  1. Hi Susan, yes probably, but I never wrote the conversion the other way. It would need to be written.
    We had a special case, where we needed to convert the BMP to ImageMagick PCL to a modified PCL for an IBM midrange computer AS400 (Series i) server program, so we could put the image (the signature) onto a point of sale invoice.
    ImageMagick made the image look opposite (black background, white lettering), so we had to fix it.

  2. Nerrrrrddddddd!

    I love it.

Submit a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Bad Behavior has blocked 708 access attempts in the last 7 days.