A Quick and Dirty Bar Code Image httpHandler
Yesterday I was trolling the ASP.NET forums killing some time and answering questions when I came across a thread where someone was seeking some help on a FREE .NET Bar Code library. Last summer I needed the same thing and was working on manipulating PDF files at the same time and worked with the iTextSharp library which does both, so I recommended it to the seeker. I checked back this afternoon and see he has found it to meet his needs, but I saw his implementation of the Bar Code image generator was using a Page class. If you know me you know I said, ugh. This should be an httpHandler! So I spent 5 minutes and created a quick and dirty Bar Code Generating httpHandler to get things started.
All the bar code generation is done in the iTextSharp bar code class itself, the httpHandler just serves it up.
AsHttpRequest = context.Request
AsHttpResponse = context.Response
Thenbc39.Code = Request(
Elsebc39.Code = Now.Month.ToString & Now.Day.ToString & Now.Year.ToString
AsSystem.Drawing.Image = bc39.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White) response.ContentType =
Of course with a custom httpHandler (not a generic handler, which would work just as well) it must be registered in the web.config file.
Finally an image needs to reference the barcode.gif file that was just mapped. It needs to be in a web page. Notice in the httpHandler code I have it check for a Code variable, if it does not exist then I just use the numerical values of the current date.
Voila, a quick and dirty Bar Code image generating httpHandler!