Creating Barcodes in Oracle Reports using Java
This Oracle Reports tutorial creates barcodes in a report using the IDAutomation Java Barcode Package and a comma-delimited file as a database source. To retrieve data from other database sources such as an Oracle Database Server, please refer to the documentation in Oracle Reports.
Buy License Download Demo Support
Compatibility
- Oracle Reports 9i or greater
This tutorial will use the class library of the IDAutomation Linear barcode Java .jar file to create temporary jpeg images of Code 128 barcodes in a report. After the barcodes are generated, the report engine deletes the temporary images. To generate 2D barcodes, simply substitute the class used in this tutorial. For example, instead of using com.idautomation.linear.encoder, use com.idautomation.datamatrix.encoder for a Data Matrix barcode.
Java Barcode Jars | Class File Path | Create Object |
LinearBarCode.jar | com.idautomation.linear.encoder | BarcodeObject := BarCode.new() |
IDADataBar.jar | com.idautomation.databar.encoder | BarcodeObject := DataBar.new() |
IDAAztec.jar | com.idautomation.aztec.encoder | BarcodeObject := Aztec.new() |
IDADataMatrix.jar | com.idautomation.datamatrix.encoder | BarcodeObject := DataMatrix.new() |
IDAMaxiCode.jar | com.idautomation.maxicode.encoder | BarcodeObject := MaxiCode.new() |
IDAPDF417.jar | com.idautomation.pdf417.encoder | BarcodeObject := PDF417.new() |
IDAQRCode.jar | com.idautomation.qrcode.encoder | BarcodeObject := QRCode.new() |
Tutorial on how to access the JAR Properties in the API.
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.)
Download Now - 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). NOTE: 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", and click Next.
- Title the report "Product Inventory". Select the "Group Above" option. Click Next.
- In the Data Source step, Highlight "Text Query", and 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 on 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.
Step 2. Adding the IDAutomation Barcode Java Component to Oracle Reports
- 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.
- 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.
- Open Oracle Reports.
- Select "Open an Existing Report". Click OK.
- Select Inventory.rdf. Click Open.
- On the Program menu item, click Import Java Classes.
- To create a Linear barcode navigate through to COM | IDAutomation | Linear | Barcode.
Click Import.
To create a 2D barcode navigate through to COM | IDAutomation | 2D Barcode Type| 2D Barcode Type. - 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 code for the corresponding symbology:
- Linear Code Example
- DataBar Code Example
- Aztec Code Example
- Data Matrix Code Example
- PDF417 Code Example
- QR Code Example
For other options, please refer to the JavaBean properties in the user manual of the product. - 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 look 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:
Symbology Code Example
Linear Barcode Example
/* name of temp file. For 1D barcodes, set to VarChar2(250). For 2D barcodes, set to VarChar2(500). */
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. This example uses the LinearBarCode.jar */
BarcodeObject := BarCode.new();
/* Set the symbology. This property setSymbologyID is only valid for the LinearBarCode.jar */
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;
DataBar Barcode Example
/*name of temp file. For 1D barcodes, set to VarChar2(250).*/
ImageFile VarChar2(500);
/*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. This example uses the IDADataBar.jar*/
BarcodeObject := DataBar.new();
/*set the data to encode*/
DataBar.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;
Aztec Barcode Example
/*name of temp file. For 2D barcodes, set to VarChar2(500).*/
ImageFile VarChar2(500);
/*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. This example uses the LinearBarCode.jar*/
BarcodeObject := Aztec.new();
/*set the data to encode*/
Aztec.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;
DataMatrix Barcode Example
/*name of temp file. Set to VarChar2(500).*/
ImageFile VarChar2(500);
/*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. This example uses the LinearBarCode.jar*/
BarcodeObject := DataMatrix.new();
/*set the data to encode*/
DataMatrix.setDataToEncode(BarcodeObject, to_char(:ProductID));
/* Encoding Mode: 0 = ASCII (default),1 = C40,2 = TEXT, 4 = BASE256 */
DataMatrix.setEncodingMode(0);
/*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;
PDF417 Barcode Example
/*name of temp file. For 2D barcodes, set to VarChar2(500).*/
ImageFile VarChar2(500);
/*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. This example uses the LinearBarCode.jar*/
BarcodeObject := PDF417.new();
/*set the data to encode*/
PDF417.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;
QR-Code Barcode Example
/*name of temp file. For 1D barcodes, set to VarChar2(250). For 2D barcodes, set to VarChar2(500).*/
ImageFile VarChar2(500);
/*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. This example uses the LinearBarCode.jar*/
BarcodeObject := QRCode.new();
/*set the data to encode*/
QRCode.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;
Related Documents:
- Before production, IDAutomation suggests verifying the result with the Barcode Decoder App.
- Barcode Integration Guide for Oracle Reports
- IDAutomation Java Barcode Package
- How to create barcodes in Oracle Reports Web Reports using the Native JavaScript Barcode Generator