Using Code 128 barcodes in XML Publisher

Code 128 barcodes are used extensively within various industries. Since they are so common, chances are you will be asked to develop reports containing this barcode at some stage (for example, within invoice statements).

This article explains in detail how to display Code 128 barcodes within XML Publisher reports. It starts with some background information on Code 128 barcodes, and then explains each step necessary to use Code 128 barcodes in XML Publisher:

  1. Finding an appropriate Code 128 font
  2. Installing the font on the local machine
  3. Installing the font on the App Server/Process Scheduler
  4. Using Code 128 font within XML Publisher RTF templates
  5. Generating XML Publisher reports containing Code 128 barcodes (by using the barcode encoding function)
  6. Testing barcodes

This article assumes you have a decent understanding and experience with XML Publisher.

Background of Code 128 barcodes

Code 128 barcodes are used for alphanumeric or numeric-only characters. The barcode itself consists of 6 sections:

  1. Quiet Zone
  2. Start Character
  3. Encoded Data
  4. Check Character
  5. Stop Character
  6. Quiet Zone

The Check Character is calculated from a weighted sum (modulo 103) of all the characters within the barcode (i.e. modulo 103 of the Start Character + all characters within Encoded Data).

To represent all 128 ASCII values, there are actually three Code 128 subtypes, which can be mixed within a single barcode (i.e. within the Encoded Data section):

  • 128A - ASCII characters 00 to 95 (0-9, A-Z and control codes) and special characters
  • 128B - ASCII characters 32 to 127 (0-9, A-Z, a-z) and special characters
  • 128C - 00-99 (double density encoding of numeric only data) and FNC1

For representing digits, subtype C is preferred as it results in barcodes which are physically smaller and easier to read than the same data recorded entirely in subtype A or B. Subtype B is preferred for alphanumeric data.

Example barcode and check character calculation

Data to encode: 01234567890A

Barcode characters StartC 01 23 45 67 89 CodeB 0 A 19 Stop
Value 105 1 23 45 67 89 100 16 33
Weights 1 1 2 3 4 5 6 7 8
cell-content 105 1 46 135 268 445 600 112 264

Sum of Products = 1976 modulus 103 = 19
Data returned by the barcode scanner: 01234567890A

For more information on Code 128 barcodes, please refer to the following sites:

STEP 1: Finding an appropriate Code 128 font

The first step is to find an appropriate Code 128 font for Microsoft Word. There are many Code 128 fonts out there (as Google searches testify), but few are free. The barcode font should be readable by your Code 128-compatible USB barcode scanner (you’ll need one for testing), and most importantly, it should be readable by the barcode scanners that will be used in the live production system. In other words, it is not enough to simply test the barcodes with your own USB barcode scanner; additional test will be needed to ensure it’ll work in the production system. For example, if you are generating invoices with barcodes on them, and these barcodes are scanned by a third-party, you’ll also need to test that their barcode scanners can actually read the barcode.

The example Code 128 font used in this article is free, and is available under the GNU General Public licence:
http://grandzebu.net/index.php?page=/informatique/codbar-en/code128.htm

STEP 2: Installing the font on the local machine

Before barcodes can be used in Microsoft Word (which is used for manipulating XML Publisher RTF templates), the Code128 barcode font needs to be installed on the developer’s local machine. This can be done by copying the downloaded font into the following directory:

C:\Windows\fonts\

STEP 3: Installing the font on the App Server/Process Scheduler

In order to generate XML Publisher reports containing barcodes, the barcode font needs to be installed on the Application and Process Scheduler servers.

Firstly, the barcode font (code128.ttf in our example) will also need to be installed in the following directory on the Application Server:

  • <server path>/fonts/truetype/

Afterwards, an XML Publisher configuration file needs to be created in the following directory, in order to make use of the new barcode font:

  • <server path>/jre/lib/xdo.cfg on the application server(s)
  • <server path>/jre/lib/xdo.cfg on the process scheduler server(s)

The XMLP config file should contain the following:

<config version="1.0.0" xmlns="http://xmlns.oracle.com/oxp/config/">
   <!-- Font setting -->
   <fonts>
      <font family="Code 128" style="normal" weight="normal">
         <truetype path="<server path>/fonts/truetype/code128.ttf " />
      </font>
   </fonts>
</config>

The information in the configuration file only overrides settings that are specified in the file.

NOTE: It is necessary to apply this config to BOTH the Application Servers and the Process Scheduler servers. XML Publisher reports can be created “on the fly” (using the Application Server), or in batch (using the Process Scheduler server) – as such, the barcode font needs to be installed on all of them.

Another approach is to add the font code settings into the properties of the Word document:

In Word 2007:

  • Office Orb > Prepare > Properties
  • Custom tab
  • Name: xdo-font.Code 128.normal.normal
  • Type: Text
  • Value: truetype.PS_HOME/fonts/truetype/code128.ttf

STEP 4: Using Code 128 font within XML Publisher RTF templates

The data to encode for the barcode should exist in the Data Source for the XML Publisher report. In our example, we’ll assume that the data source is a Rowset, and that the field name for barcode data is BARCODE.

To use barcodes within your RTF template, first load the template’s Data Source which contains barcode data (XSD file).

Then insert the barcode field in your template (using the XML Publisher Word template builder add-in), like this:
barcode_field.jpg

Then, change the font for the newly-inserted barcode field (i.e. <BARCODE>). It will then look like this:
barcode_field_code_128.jpg

Save your RTF template, and upload it into the XML Publisher report definition.

Please note: When this RTF template is modified, it is necessary to first remove the barcode field and add it again in the same spot (in Code 128 font); i.e. repeat the steps outlined in this section. Otherwise, the barcode may not display correctly when the report is generated.

STEP 5: Generating XML Publisher reports containing Code 128 barcodes

Now that the RTF template contains the barcode field, use PeopleCode to generate the XML Publisher report. When generating the report, encode the barcode data (i.e. BARCODE field) before passing it to the template. This is done via the getCode128BarCode function. For example:

&DataSourceRowset(1).REC.BARCODE.value =  getCode128BarCode(RECB.BARCODE.Value);

This function puts start and stop characters, checksum character, and code shift characters if necessary (i.e. from subtype C to subtype B and vice versa). This means that you don’t have to worry about the structure of Code 128 barcodes – all of that is handled within this function.

The getCode128BarCode function code is provided here:

getCode128BarCode.pcode

The getCode128BarCode function is based upon the code provided on GrandZebu for the Code128 function (scroll about half way down): http://grandzebu.net/index.php?page=/informatique/codbar-en/code128.htm

STEP 6: Testing barcodes

As discussed in Step 1, it is necessary to ensure that generated barcode can be read by the relevant barcode scanners.

To test the barcode, print out the generated XML Publisher report and try scanning it with a Code-128 compatible USB barcode scanner. Ensure the expected data is read. Also, ensure barcodes can be scanned by the equipment used in the live production system.

Other notables:

  • Test for different lengths of the barcode
  • Be aware of barcode size requirements for third-party systems

Darko Jovanovic
PeopleSoft Consultant

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License