Creating Barcodes in Oracle Reports using JavaIBM Partner Logo

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
  1. 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
  2. In a text editor (such as Notepad), Open InventoryPDS.txt. Make sure Reports Builder is closed.
  3. 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.)
  4. Copy the text from InventoryPDS.txt to textpds.conf. This data should be copied before the line "</textPDS>".
  5. Save and close both text files.
  6. Start Reports Builder.
  7. Ensuring the "Use Report Wizard" option is highlighted, click OK.
  8. If the "Welcome to the Report Wizard" screen is displayed, click OK.
  9. Select "Create Paper Layout Only", click Next.
  10. Title the report "Product Inventory". Select the "Group Above" option. Click Next.
  11. In the Data Source step, Highlight "Text Query", click Next.
  12. Click the Query Definition button.
  13. Find ProdInvCSV in the drop-down list under Data Definition.
  14. 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.
  15. Click Next on the "Data Source Definition" page of the Report Wizard.
  16. Move Category to the "Group Fields" list by highlighting Category and clicking the right arrow (>). Click Next.
  17. Click the double right arrows (>>) to move all fields to the list of Displayed Fields. Click Next.
  18. Click Next on the Totals page of the Wizard.
  19. Click Next of the Labels page of the Wizard.
  20. Select the color for the Predefined Template of the report. Click Next.
  21. Click Finish. The report should be available in design view.
  22. Save the report as Inventory.jsp.
Step 2. Adding the IDAutomation Barcode Java Component to Oracle Reports
  1. Ensure Oracle Reports is not running.
  2. Save LinearBarCode.jar to an easy-to-remember location. For example, C:\ClassPath
  3. Update the REPORTS_CLASSPATH environment variable to include the JAR file.
    1. 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.
    2. For Linux and UNIX systems: update and save the REPORTS_CLASSPATH environment variable.
  4. Open Oracle Reports.
  5. Select "Open an Existing Report". Click OK.
  6. Select Inventory.rdf. Click Open.
  7. On the Program menu item, click Import Java Classes.
  8. 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.
  9. Navigate through to COM | IDAutomation | Linear | Encoder | barCodeEncoder. Click Import.
  10. 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.
    Oracle report editor
  11. Click on the Formula Column object in the toolbar.
  12. Draw a Formula Column object in the G_Product pane of the Data Model viewer.
    Inventory Report Editor
  13. Double-click the new Formula Column field to bring up the Property Inspector window.
  14. Change the Data Type property to Character.
  15. Click the formula box next to the PL/SQL Formula property in the Property Inspector. This will open the PL/SQL editor.
  16. Replace the code between the function definition and 'end;' with the code for the corresponding symbology:
    1. Linear Code Example
    2. DataBar Code Example
    3. Aztec Code Example
    4. Data Matrix Code Example
    5. PDF417 Code Example
    6. QR Code Example
    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.
  17. Compile the code in the PL/SQL editor to ensure there are no errors and close the PL/SQL window.
  18. Open the Page Layout for the report by double-clicking the icon next to Paper Layout in Object Navigator.
  19. 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.
    Page_layout_barcode.gif
  20. 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.
  21. Save the report.
  22. Select Compile | All option from the Program menu. At this point, the report should be ready to preview.
  23. Select Program | Run Paper Layout from the Report Builder menu.
  24. 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:
    Barcode report

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: