Creating Barcodes in Oracle using Java
The implementation tutorial presented here creates barcodes using
the IDAutomation Java Barcode
Package. This example creates a report in page layout using the
Linear Java Barcode Package and a comma delimited file as a database
source. If in need of creating 2D barcodes, simply substitute the class
used in this tutorial. For example, instead of using
com.idautomation.linear.encoder, use
com.idautomation.pdf417.encoder instead
for a PDF417 barcode. To retrieve data from other database sources such
as an Oracle Database Server, please refer to the documentation in Oracle
Reports.
To follow along with this example, Oracle Reports 9i, 10g or greater
is required. This tutorial will use the class library of the
IDAutomation Linear barcode
Java .jar files to create temporary jpeg images of barcodes to be
included in a report. The report engine deletes the temp image files
after the report is run.
Step 1. Creating a report using a comma-delimited data
source
-
Download and save the text files, ProductInv.txt and
InventoryPDS.txt, required for implementing this example
here. (InventoryPDS.txt is the pluggable data source definition
file and ProductInv.txt is the file containing the data that will
be included in the report.)

- In a text editor (such as Notepad), Open InventoryPDS.txt.
- Make sure Reports Builder is closed.
- Start another text editor session and Open textpds.conf.
This file will be in the Oracle_Home/reports/conf directory.
This file enables Reports Builder to recognize ProductInv.txt as
a Pluggable Data Source (PDS). (Please note that the Oracle_Home
directory path is the home directory of all Oracle applications
and was set at the time Oracle Reports was installed.)
- Copy the text from InventoryPDS.txt to textpds.conf. This data
should be copied before the line "</textPDS>".
- Save and close both text files.
- Start Reports Builder.
- Ensuring the "Use Report Wizard" option is highlighted,
click OK.
- If the "Welcome to the Report Wizard" screen is displayed,
click OK.
- Select "Create Paper Layout Only", click Next.
- Title the report "Product Inventory". Select the "Group Above"
option. Click Next.
- In the Data Source step, Highlight "Text Query", click
Next.
- Click the Query Definition button.
- Find ProdInvCSV in the drop-down list under Data Definition.
- Click the Browse button under Data Source. Navigate to
the location of ProductInv.txt. Ensure that the Files of Type
box reads TXT files. Click OK in the Define Text Query
box.
- Click Next on the "Data Source Definition" page
of the Report Wizard.
- Move Category to the "Group Fields" list by highlighting
Category and clicking the right arrow (>). Click Next.
- Click the double right arrows (>>) to move all fields
to the list of Displayed Fields. Click Next.
- Click Next on the Totals page of the Wizard.
- Click Next of the Labels page of the Wizard.
- Select the color for the Predefined Template of the report.
Click Next.
- Click Finish. The report should be available in design
view.
- Save the report as Inventory.jsp.
- Ensure Oracle Reports is not running.
- Save LinearBarcode.jar to an easy-to-remember location.
For example, C:\ClassPath.
- Update the REPORTS_CLASSPATH environment variable to include
the JAR file.
- For Windows systems: Update the REPORTS_CLASSPATH
registry entry for Oracle Reports. This registry entry tells
Oracle Reports where to find .jar files containing classes that
Oracle Reports will be able to use. NOTE: This step requires
updating the Windows registry. IDAutomation recommends creating
a backup of the registry before continuing.
Search the registry for REPORTS_CLASSPATH key value. Double-click
REPORTS_CLASSPATH. Edit the value by adding the name of the
full filename and path of the jar file, e.g. C:\ClassPath\LinearBarcode.jar;.
Ensure there is a semi-colon at the end. Click OK and close
the registry.
- For Linux and UNIX systems: update and save the REPORTS_CLASSPATH
environment variable.
- Open Oracle Reports.
- Select "Open an Existing Report". Click OK.
- Select Inventory.rdf. Click Open.
- On the Program menu item, click Import Java Classes.
- Navigate through to COM | IDAutomation | Linear | Barcode.
Click Import.
- Navigate through to COM | IDAutomation | Linear | Encoder
| barCodeEncoder. Click Import.
- In Object Navigator, double click the icon next to Data Model
to open the Data Model editor.
A display similar to the following image should show up.

- Click on the Formula Column object in the toolbar.
- Draw a Formula Column object in the G_Product pane of the Data
Model viewer.

- Double click the new Formula Column field to bring up the
Property Inspector window.
- Change the Data Type property to Character.
- Click the formula box next to the PL/SQL Formula property
in the Property Inspector. This will open the PL/SQL editor.
- Replace the code between the function definition and 'end;'
with the following code:
/******************************************************************/
/*name of temp file*/
ImageFile VarChar2(250);
/*object containing barcode properties*/
BarcodeObject ORA_JAVA.JOBJECT;
/*object that creates jpeg of barcode based
on BarcodeObject*/
BarcodeEncoderObject ORA_JAVA.JOBJECT;
begin
/*Get a temporary file name for the jpeg*/
/*On Solaris Unix, use the following code
to create the temp file: ImageFile := srw.create_temporary_filename()
|| '.jpg'; */
imageFile := srw.create_temporary_filename();
/*Create the barcode object*/
BarcodeObject := Barcode.new();
/*Set the symbology*/
Barcode.setSymbologyID(BarcodeObject, Barcode.CODE128);
/*set the data to encode*/
Barcode.setDataToEncode(BarcodeObject, to_char(:ProductID));
/*Create the jpeg*/
BarcodeEncoderObject := BarcodeEncoder.new(BarcodeObject, 'JPEG',ImageFile);
/*If, for some reason, the barcode is not
created, return null
otherwise, return the name of the barcode image jpeg that was
created */
if ORA_JAVA.IS_NULL(BarcodeEncoderObject) then
return(NULL);
else
return(ImageFile);
end if;
/******************************************************************/
Please note that this is the area where other properties, i.e. Left
Margin, Top Margin, Human Readable Text Visibility, etc., of the
barcode image can be set. To size the barcode, use the methods setXDimensionCM
to increase the width (X dimension) and setBarHeightCM to increase
the height.
For other options, please refer to the JavaBean properties in the
user manual of the product. Online versions of the manuals are
located here.
- Compile the code in the PL/SQL editor to ensure there
are no errors and close the PL/SQL window.
- Open the Page Layout for the report by double clicking
the icon next to Paper Layout in Object Navigator.
- Ensuring that the table is selected in the Paper Layout,
drag a Field Object from the Toolbox onto the form. The display
should appear similar to the image below.

- Double-click the new Formula Field, F_1, to bring up
the Property Inspector. Set the following properties:
--Select CF_1 from the dropdown list for the Source Property.
--Select Character from the dropdown list for the DataType Property.
--Set the ReadFromFile Property to 'Yes'.
--Set the FileFormat Property to Image.
- Save the report.
- Select Compile | All option from the Program menu. At
this point the report should be ready to preview.
- Select Program | Run Paper Layout from the Report Builder
menu.
- Make adjustments to the layout, formatting, and size of the
fields, if necessary, in the report using the Report Layout Editor.
The final report should look similar to the following image:

|