19 May 2015 Tuesday

XPages: Create Code39 Barcodes

Hi Folks,

a couple of weeks back a customers asked me how to do Barcodes in XPages as they needed them in their application to be printed to a document scanning system. After looking into the application, I realized that they had been using a Code39 barcode font in Notes previously to create barcodes in the Notes Client. So I went looking for an alternative for XPages and eventually came across Code39.js, a small JavaScript library that was able to do the trick. The JS library can be found here: http://www.lutanho.net/

For a quick sample, I just created a new CSJS library in an empty database and pasted the code from above into it. Then, additionally, I had to add the two gifs to the images resources:

Image:XPages: Create Code39 Barcodes

Both files are part of the zip package, you can download from the link above.

My sample XPage has an Input Control to enter text and a Script Block to show the code39 of the text the user enters:

Image:XPages: Create Code39 Barcodes

Here's the sample Code of the XPage:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

             <xp:script src="/code39.js" clientSide="true"></xp:script>
     <xp:panel id="outerPanel">
                                     <xp:label value="Have a say !" id="inputLabel"></xp:label>
                                     <xp:inputText id="inputToCode39" defaultValue="Something to say" value="#{sessionScope.MyInput}"></xp:inputText>
                                     <xp:button value="Refresh !" id="button1">
                                             <xp:eventHandler event="onclick" submit="true"
                                     <xp:label value="Your say in Code39"
                                     <xp:panel id="outputPanel">
                                             <xp:scriptBlock id="scriptBlockCode39">
                                                     <xp:this.value><![CDATA[var text_entered = document.getElementById("#{id:inputToCode39}").value;
if(text_entered==null) {
     text_exntered = "Please enter some text !";


This is a very simple example to do the job. If you want to try out the live sample - here it is:  


regards, Heiko.
Heiko Voigt   |   19 May 2015 14:00:00   |    xpages  javascript  domino  barcode    |  
  |   Next Document   |   Previous Document

Discussion for this entry is now closed.

Comments (4)

Jesper Kiaer    http://nevermind.dk    19.05.2015 22:36:01

Nice :-)

fatih duranoglu       20.05.2015 9:29:10

really good thanks Heiko. how can we read code39 barcode with mobile phone camera etc.

Heiko Voigt    http://www.sit.de    20.05.2015 10:54:25

Hi Fatih, not sure what you are looking for exactly - the generated barcodes can be read by any barcode scanner app on your smartphone app of choice. I use this one on my BlackBerry Passport https://appworld.blackberry.com/webstore/content/48843/?lang=en&countrycode=DE Now, if you are looking to capture a barcode into an xpages mobile app, that's a totally different beast ;-). Regards, Heiko.

Patrick Kwinten    http://quintessens.wordpress.com    21.05.2015 9:13:32

Hi Heiko, thanks for sharing! This looks really easy and from field experience these types of solutions come in very handy e.g. labbeling products for logistics etcetera. With a Notes product database in the back end I can think of some use cases.