Barcodes with JpGraph

Introduction

With the barcode extension to JpGraph you can now easily create barcodes using all the commonly accepted symbologies. You can choose to have the resulting barcode being created as an image (in either PNG or JPEG format) or as a Postscript file ready for printing on high resolution printers. The barcode extension provides extensive data verification which makes sure you can't create an invalid barcode.

Verification

All generated barcodes (except CODE 11) have been extensively verified using Metrologic CCD-47 handheld scanner.

Features

This is a summary of the features available in the JpGraph barcode extension.

Sample application

Even though primarily the JpGraph barcodes are meant, and designed, to be used as a library within a larger system there is a small demo barcode creation application included in the distribution. This application can be used to easily create barcode through it's WEB interface.

This application is primarily included as a demo on the features available and not as a finalized product.

You can find the application in the "barcode/" subdirectory in the distribution.

Creating barcodes - Quick start

All barcode creation follows the follwing simple steps :
  1. Create an encoder for you choose of symbology
  2. Create a backend for your choosen output format
  3. Encode your data
So for example to create an image barcode representing the data string "ABC123" using symbology "CODE 39" you would have to write Stroke('ABC123');'; ShowCodeSnippet($s); ?> As you can see from the code above the basic interface to the library makes use of two abstract factories which creates the appropriate encoder and output backend. This design makes the addition of new output formats and new symbologies transparent for the end user of the library.

If you instead wanted to encode the data string using symbology "CODE 128" instead, you would only have to modify the first line in the above code snippet to

Adjusting the output

As mentioned in the introduction you have some flexibility in how the generated barcodes is formatted. Two common modifications is to either change the module width used (=the width of a unit line in the bar) or supress the printing of the human readable version of the data string.

To adjust the module width you make use of the "SetModuleWidth()" method of the backend. So for example to augument the previous example and change the module width to 2 and hude the human readable text we would change the code to SetModuleWidth(2); $barcode->HideText(); $barcode->Stroke('ABC123');'; ShowCodeSnippet($s); ?> A note on the module width might be in order here. For image type backends this specifies the number of pixels used for a module and for Postscript (and Encapsulated PS) this specifies the width in points (i.e. 1/72 inch). This also means that for image type backends only integer values makes sense.

You should keep in mind that depending on the quality of the printer (and paper) very small module width might not be readable with all barcode readers. For images it is therefore recommended to use "2" pixels as the minimum module width and for postscript output the minimum recommended width is "0.8" pt.