Skip to Content

image

As you know, the holidays drove me to Tyrol this year. One day, we visited Innsbruck. It struck me that lots of people over there had a tattoo. It sounds silly, but in the countryside where I live for nearly 15 years now, most of the tattoos that I see are branded on animals. It’s interesting to see myself turning from a city boy – born and raised in Brussels – to a redneck (I burn easily in the sun). I even bake my own bread with one of those baking machines , and compost the garden with leftovers myself.
OK, where was I? Oh yes, tattoos. As I said, we don’t see them a lot over here and the only tattoos I saw in my childhood belonged to Popeye and – if I recall well – Captain Haddock. These days, tattoos are in (apparently). The most eye catching was a man who had a bar code tattoo.

         

 

         

The muse

         

Coincidently, a week later one of those light-hearted summer talk shows where a guy called Dinand Woesthoff from the music group Kane told the host that he has a tattoo of his first album on his inner arm. Very interesting.
Was this a sign that I needed to write something on barcodes? Dries already wrote a web log on Integrating barcodes in webpages. and John and Sheng have written a series on RFID. Speaking of RFID. IMEC ( Interuniversity MicroElectronics Center ) / K.U. Leuven just (at the moment of writing) published a breakthrough in the research on organic (plastic) RFID in order to lower the production price and replace barcodes in the long term.
For now, I want to show you another simple method for creating barcodes for your BSP application. In fact, once you have installed the software you only need to write a minute piece of coding once in order to make it work.

         

 

         

All you need is

         

JpGraph , an Object-Oriented Graph creating library for PHP. I used this tool quite intensively at my previous work. As with all web development tools, Coldfusion had rather limited charting capabilities. We used it the Die Mensch-Maschine EDI used PHP for creating CAPTCHAs: do as much as possible in the main web development tool and let the external PHP create the file with the graphical image. This will be the same method we’re going to follow now.
  First things first though, we need to obtain JpGraph. This package comes in two flavours: a QPL 1.0 (Qt Free Licensee) for non-commercial, open-source or educational use and JpGraph Professional License for commercial use. The first license contains everything for charting, but I will elaborate on that in a later web log or article. The professional license costs 85€ (+VAT) and additionally contains the windrose, tachometer and barcode modules. The latter is the thing that interests us. The barcode supports the following formats:

         

               

  • UPC A
  •            

  • UPC E
  •            

  • EAN 128
  •            

  • EAN 13
  •            

  • EAN 8
  •            

  • CODE 11 (USD-8)
  •            

  • CODE 39
  •            

  • CODE 128
  •            

  • Industrial 2 of 5
  •            

  • Interleaved 2 of 5
  •            

  • Codabar
  •            

  • Bookland (ISBN)
  •          

         

All this is put in a JPEG, PNG or (encapsulated) postscript file.
  Enough commercial talk, let’s start with some action.

         

 

         

Killer dwarf code

         

Installing the package according to the manual is dead easy. The only points you must pay attention to are the minimum PHP requirements (PHP 4.3.1) and the permissions for caching.
Once that is done, you need to make a PHP script that’ll create your barcode. Let’s take an ISBN barcode as example. Read very carefully, I’m going to write this only once:

         

<?php 
if ($argc != 3) { 
die ("
 please provide filename and data"); 
} 
else 
{ 
$file= $argv[1]; 
$data= $argv[2]; 
// choose the barcode type 
$symbology = BarcodeFactory ::Create(ENCODING_BOOKLAND); 
// create the barcode 
$barcode = BackendFactory ::Create(BACKEND_IMAGE, $symbology); 
// and write the file 
if( $barcode ->Stroke($data, $file)===false ) { 
die ("
 error writing file"); 
} 
} 
?> 

         

 

         

That’s it. You can opt for setting the encoding as a parameter too. The possible values are:

         

               

  • ENCODING_EAN128
  •            

  • ENCODING_EAN13
  •            

  • ENCODING_EAN8
  •            

  • ENCODING_UPCA
  •            

  • ENCODING_UPCE
  •            

  • ENCODING_CODE39
  •            

  • ENCODING_CODE93
  •            

  • ENCODING_CODE128
  •            

  • ENCODING_CODE25
  •            

  • ENCODING_CODEI25
  •            

  • ENCODING_CODABAR
  •            

  • ENCODING_CODE11
  •            

  • ENCODING_POSTNET
  •            

  • ENCODING_BOOKLAND
  •          

         

 

         

As you can see it’s child’s play. EDI already elaborated on what to do on the BSP in his Die Mensch-Maschine. It boils down to creating an external command in SM69 for the PHP script and calling it via the FM ‘SXPG_COMMAND_EXECUTE’ with the 2 parameters. The only difference here is that you can’t immediately delete the resulting file. It’s best not to do so since JpGraph has its own caching mechanism. See the manual for this. I would suggest that you schedule a script or a crontab that deletes the content of all files older than 12 hours.

         

 

         

Conclusion

         

I’ve ran this PHP with the book I’ve just finished. A tip, if you want to know which one:

         

1-V-116-44-11-89-44-46-L-51-130-19-118-L-32-118-116-130-28-116-32-44-133-U-130.

         

For the record, I’ve blown up and retouched the result a bit in order for it to fit it in better in this web log. This is the result.

         

image

         

As you can see, this is yet another example on how external tools can be very helpful and how PHP and SAP can coexist perfectly without a lot of effort.

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply