How to Generate 2D Barcode / QR Code in Oracle Reports (Doc ID 1678110.1)

How to Generate 2D Barcode / QR Code in Oracle Reports (Doc ID 1678110.1)

APPLIES TO:

Oracle Reports Developer – Version 11.1.1.1.0 and later
Information in this document applies to any platform.

GOAL

Generate an Oracle Report output with 2D Barcode / QR Code image.

SOLUTION

NOTE: The sample program in this article is provided for educational purposes only and is NOT supported by Oracle Support Services. It has been tested internally and works as documented. Oracle can not guarantee that it will work in all possible configurations, so be sure to test it thoroughly in your test environment before deploying it.

 

Since 10gr2 , it is possible to import Java classes in Oracle Reports.

Reports Builder Online Help :
The Java Importer enables you to access the rich environment of the Java programming language from your reports.
 Using the Java Importer, you can automatically generate PL/SQL packages and procedures to access Java classes and then program with the generated PL/SQL in your reports.

Open Source Java Libraries exist to generate 2D Barcode / QR Code / Data Matrix  : XZing , QRGen , Barcode4J , …

The example below is based on the Open Source Java libraries : XZing and QRgen :

XZing   https://github.com/zxing/zxing
QRGen https://github.com/kenglxn/QRGen

To download the Jar files core-1.7.jar , javase-1.7.jar, and qrgen-1.2.jar used in this example please follow the following steps:

[1] core-1.7.jar and javase-1.7.jar files can be downloaded at :

ZXing  https://github.com/zxing/zxing/wiki/Getting-Started-Developing#just-need-a-jar under the following section:
Just Need a JAR?  
    If you just need a pre-built JAR file, you can always find compiled resources from the Maven release repository, including recent snapshot/nightly builds.

[2] qrgen-1.2.jar can be downloaded at :

QRGen  https://github.com/kenglxn/QRGen#get-it under the following section:
Get it:
    QRGen consists of three modules: core, javase and android. Everything is available from Maven Central Repository.

Note :
1. The example below is written using the Windows platform syntax. The same example can be implemented on “UNIX” platforms.
2. The Jar file names may be different according to the versions of ZXing and QRGen used.
3. The java classes in some jar files of the latest versions of ZXing / QRGen have been generated by the java Compiler 7.
The JDK provided by default in ORACLE_HOME\jdk is the JDK 6.
Classes compiled with the Java compiler 7 cannot be used with the JDK 6The jar files used in this example (core-1.7.jar , javase-1.7.jar , qrgen-1.2.jar) have been used with the default JDK provided in ORACLE_HOME\jdk for FMW 11gR1 and 11gR2

 

The following are the steps to build a report to generate 2D barcodes

Step 1 . Create the Java code file qrcode.java

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;public class qrcode {
public static void main(String[] args) {
/* This is an example */
try {
generate (“http://www.oracle.com” , “c:\\temp\\qrcode_temp.gif”);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void generate(String qrcodetext , String imagefilename)
throws Exception
{
ByteArrayOutputStream out = QRCode.from(qrcodetext).to(ImageType.GIF).stream();
FileOutputStream fout = new FileOutputStream(new File(imagefilename));
fout.write(out.toByteArray());
fout.flush();
fout.close();
}
}

Step 2 . Copy the jar files core-1.7.jar , javase-1.7.jar, and  qrgen-1.2.jar in the directory %ORACLE_HOME%\reports\jlib

Step 3 . Compile this java class using the java compiler in %ORACLE_HOME%\jdk\bin

set CLASSPATH=%ORACLE_HOME%\reports\jlib\core-1.7.jar;%ORACLE_HOME%\reports\jlib\javase-1.7.jar;%ORACLE_HOME%\reports\jlib\qrgen-1.2.jar
%ORACLE_HOME%\jdk\bin\javac qrcode.java

Step 4 . Copy the file qrcode.class generated in Step 3. in %ORACLE_HOME%\reports\jlib directory

 

Step 5 . Make sure REPORTS_CLASSPATH environment variable includes %ORACLE_HOME%\reports\jlib folder where qrcode.class file is located
Step 6 . Import the java class qrcode in the RDF

Step 7 . Create a Formula column in the Reports calling the Java Code :

function CF_1Formula return Char is
image_file_name VARCHAR2(1000);
begin
image_file_name := SRW.CREATE_TEMPORARY_FILENAME ;
qrcode.generate (:DATA , image_file_name);
return(image_file_name);
end;

Step 8 . In the Reports layout , create a Field with the properties :

Source : <The Formula Column created in Step 7>
Read from File : Yes
File Format : Image
Step 9 . Modify the Reports Server configuration in order to add/modify the classPath Reports engine attribute :

<engine minEngine=”1″ maxIdle=”30″ maxEngine=”1″ id=”rwEng” engLife=”50″ class=”oracle.reports.engine.EngineImpl” classPath=”D:\oracle\fmw11r1\oracle_fr\reports\jlib;D:\oracle\fmw11r1\oracle_fr\reports\jlib\core-1.7.jar;D:\oracle\fmw11r1\oracle_fr\reports\jlib\javase-1.7.jar;D:\oracle\fmw11r1\oracle_fr\reports\jlib\qrgen-1.2.jar”>

The classPath attribute value should contain (at least)  the 3 jar files required (core-1.7.jar , javase-1.7.jar and qrgen-1.2.jar) and the directory containing the class qrcode.class created in Step 3.

If you want to test the RDF in the Reports Builder , the 3 jar files required (core-1.7.jar , javase-1.7.jar and qrgen-1.2.jar) and the directory containing the class qrcode.class created in Step 3 must be added (if necessary) to REPORTS_CLASSPATH

The file QRCODE.zip in attachment contains the files :

qrcode.java : the java source of the class qrcode
qrcode.class : the class qrcode
qrcode.rdf  : a RDF in which qrcode.class has been imported and a Formula has been created to call this java code.
qrcode.pdf : a PDF generated using qrcode.rdf

REFERENCES

BUG:8401811 – ENH: NEED ABILITY TO DISPLAY AND PRINT TWO-DIMENSIONAL (2D) BARCODES
NOTE:1269490.1 – Support For 2D Barcode in Oracle Reports
NOTE:1554189.1 – Is it Supported to Upgrade the JDK in the ORACLE_HOME of an 11gR1 or 11gR2 Forms & Reports Installation to JDK 1.7.0_XX ?
NOTE:278044.1 – How to Debug REP-1401 when Executing Reports with Barcode Java Code

Advertisements

Oracle REP-0300, REP-0069, REP-57054, REP-300

Error

Forcing NLS_NUMERIC_CHARACTERS to: ‘.,’ for XDO processing

APPLLCSP Environment Variable set to :

Current NLS_LANG and NLS_NUMERIC_CHARACTERS Environment Variables are :
American_America.AL32UTF8

‘.,’

Enter Password:
REP-0300: ORACLE error occurred.
REP-0069: Internal error
REP-57054: In-process job terminated:Terminated with error:
REP-300: ORACLE error occurred.

 

Solution

Check the data type of your parameter in RDF it is date or not and what was the format mask.