2D Barcodes in Oracle Reports - A Complete Insight

Start Here

Get in touch with a
TriCore Solutions specialist

Blog | Aug 27, 2015

2D Barcodes in Oracle Reports - A Complete Insight

A 2D (two-dimensional) barcode is a graphical image that stores information both horizontally and vertically. Popularly known as quick response codes, these barcodes enable fast data access. These are often used in conjunction with the smart phones.


What are 2D Barcodes? 

A 2D (two-dimensional) barcode is a graphical image
that stores information both horizontally and vertically. As a result of that construction, 2D codes can store up to 7,089 characters. A significantly greater storage than is possible with the 20-character capacity of a unidimensional barcode.

Popularly known as quick response codes, these barcodes enable fast data access. These are often used in conjunction with the smart phones. A user needs to simply photograph a 2D barcode with the camera on a phone equipped with a barcode reader. The reader interprets the encoded URL that directs the browser to the relevant information on a website. This capability has unleashed the use of 2D barcodes in the mobile marketing phenomenally.

How to implement?                                                                                                              

I have recently received questions from one of our client on support for the Quick Response (QR) codes. You know them they are everywhere you look, even here!

To start with we need to know the 2D barcodes and their requirements for encoding and rendering. Once you have the encoding class set up in your environment it’s pretty simple to add the 2D barcode encoding code.

Many ask, how does Publisher handle QR codes? In theory, exactly the same way it handles any other 2D barcode font. You need the font file, a mapping entry and an encoding class. With those three pieces you can embed QR codes into any output.

XML Publisher does not yet license fonts for 2D barcodes. I have been working with the PDF417 and Data Matrix fonts available from IDAutomation. Along with the fonts they also provide helpful java classes to do all the encoding that is needed. It’s just a case of making their classes available in your environment and calling them in your encoding class. And, then with a neat trick in your RTF template, you can have funky 2D barcodes in your output.

Here is your step by step guide:

Step 1: Get the barcodes and encoding classes

You will need to license the fonts from the vendor. In this example I worked with the sample fonts available from the IDAutomation site.PDF417 Font – found at - http://www.advancemeants.com/downloads/IDAutomation_PDF417FontEncoderDEMO.zip - you'll get a zip file with the font and java class plus a bunch of other useful integration tools. All you need is the PDF417Encoder.class and the IDAutomationPDF417nX.ttf font from the AdditionalFonts.zip where 'X' is the X to Y ratio of the font shape, 3 is the standard.

For a more detailed explanation you can go to http://www.idautomation.com/fonts/pdf417/faq.html#Specifications

(**Explore the above links at your own risk. TriCore is not responsible for any third party websites/links)

Step 2: Update your XMLP encoding class

Now you will need to add the encoding code to your encoding class. In the encoder class, we import the font vendors encoding class and add an entry for the pdf417 font

      import IDautomationPDFE.PDF417Encoder;
      ENCODERS.put("pdf417",mUtility.getClass().getMethod("pdf417", clazz));

and create a pdf417 method that just calls the class provided by the font vendor:


  public static final String pdf417( String DataToEncode )
       PDF417Encoder pdfe = new PDF417Encoder();
       return ( pdfe.fontEncode(DataToEncode) );

Compile and deploy to the server as normal.

Step 3: Use the font in your template

Install your font into the <<WINDOWS_HOME>>/fonts directory and fire up MSWord. Then register the barcode font into as per standard process. Create your template and for the data that you wish to use the barcode for:

Now you have the data encoder and the font in place and mapped; you can use it in the template. The two commands you will need to have present are:

<?register-barcode-vendor:'ENCODER WRAPPER CLASS'; 'ENCODER NAME'?>

for my encoder I have:

<?register-barcode-vendor:'oracle.psbi.barcode.BarcodeUtil'; 'MyBarcodeEncoder'?>

Notice the two parameters for the command. 
The first provides the package 'path' and class name.
The second is the name of the encoder, in my case 'MyBarcodeEncoder'.
This command needs to be near the top of the template.

The second command is the encoding command:



Would it be right to say if 2D barcodes will replace the conventional 1D barcodes? Then the answer is no. Both the technologies will co-exist as both have their uses. 1D barcodes have the advantage in low capacity applications like the serial numbers. Though 1D barcodes hold a smaller amount of data it is 'spread' over the whole height of the barcode. If your application needs only a few characters (up to about 15) then a 1D barcode is a better Option.

On the other hand, the compact size and the ability to encode multiple fields into a single barcode are some of the major benefits of a 2D technology. One can encode more characters in a smaller space. Another benefit is that a 2D barcode can be read from any direction as well as scanned from different angles.

If you have any queries for our experts then click on the link below and submit the same:

Ask the Experts