{"id":3606,"date":"2011-04-14T20:55:56","date_gmt":"2011-04-14T15:25:56","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3606"},"modified":"2011-12-18T19:06:27","modified_gmt":"2011-12-18T13:36:27","slug":"generating-ean-8-standard-barcode-using-barcode4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/generating-ean-8-standard-barcode-using-barcode4j\/","title":{"rendered":"Generating EAN-8 standard barcode using Barcode4J"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In one of my project i needed to generate EAN-8 standard bar-code for identifying the various products. I searched for various libraries available for generating bar-code and found a library to do so. The library i used for generating the bar-code is Barcode4J.<br \/>\nYou can download it from <a href=\"http:\/\/barcode4j.sourceforge.net\/\">here<\/a><\/p>\n<p>\nBarcode4J is a flexible generator for barcodes written in Java. It&#8217;s free, available under the <a href=\"http:\/\/www.apache.org\/licenses\/LICENSE-2.0\">Apache License, version 2.0<\/a>.<br \/>\nThe bar-code generated with the help of of this library uses eight digit number hence EAN-8.<\/p>\n<p>To generate bar-code image from this library is quite simple. Just put the <strong>barcode4j.jar<\/strong> in the lib folder of the application.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>Code to generate image is:-<\/p>\n<p>[java]<br \/>\npublic File generateBarcode(Long codeDigits){<br \/>\ntry {<br \/>\n      \/\/&#8217;codeDigits&#8217; is the code for which we want to generate bar-code image<br \/>\n     EAN8Bean bean = new EAN8Bean();<br \/>\n     final int dpi = 150;<br \/>\n     bean.setModuleWidth(UnitConv.in2mm(1.0f \/ dpi));<br \/>\n     bean.setFontSize(2.0)<br \/>\n     bean.doQuietZone(true)<br \/>\n     File outputFile = new File(filepath) \/\/ existing file in the file system<br \/>\n     OutputStream out = new FileOutputStream(outputFile)<\/p>\n<p>     \/\/ class to convert provided image into barcode image<br \/>\n     BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, &quot;image\/jpeg&quot;, dpi,   BufferedImage.TYPE_BYTE_BINARY, false, 0)<br \/>\n     bean.generateBarcode(canvas, codeDigits)<br \/>\n     canvas.finish()<br \/>\n     return outputFile<br \/>\n}<\/p>\n<p>[\/java]<\/p>\n<p>So, here it takes a file from the file system and convert it into the required barcode image. Now, the user can simply display this image on the items.<br \/>\n<br \/>\nIn my case, i needed to generate a bar-code image for each product, so i create new file for every item, and stored it on the file system with unique name.<\/p>\n<p>\nThis works in my case.<br \/>\nHope it helps<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>Cheers..!!!<br \/>\nVishal Sahu<br \/>\nvishal@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In one of my project i needed to generate EAN-8 standard bar-code for identifying the various products. I searched for various libraries available for generating bar-code and found a library to do so. The library i used for generating the bar-code is Barcode4J. You can download it from here Barcode4J is a flexible generator [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[708],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3606"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3606"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3606\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}