Home: Products: Oracle Reports Barcode Implementation with Java:


Creating Barcodes in Oracle Reports using the Java Barcode Package

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 pluggable 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.)
  2. In a text editor (such as Notepad), Open InventoryPDS.txt.
  3. Make sure Reports Builder is closed.
  4. 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.)
  5. Copy the text from InventoryPDS.txt to textpds.conf. This data should be copied before the line "</textPDS>".
  6. Save and close both text files.
  7. Start Reports Builder.
  8. Ensuring the "Use Report Wizard" option is highlighted, click OK.
  9. If the "Welcome to the Report Wizard" screen is displayed, click OK.
  10. Select "Create Paper Layout Only", click Next.
  11. Title the report "Product Inventory". Select the "Group Above" option. Click Next.
  12. In the Data Source step, Highlight "Text Query", click Next.
  13. Click the Query Definition button.
  14. Find ProdInvCSV in the drop-down list under Data Definition.
  15. 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.
  16. Click Next on the "Data Source Definition" page of the Report Wizard.
  17. Move Category to the "Group Fields" list by highlighting Category and clicking the right arrow (>). Click Next.
  18. Click the double right arrows (>>) to move all fields to the list of Displayed Fields. Click Next.
  19. Click Next on the Totals page of the Wizard.
  20. Click Next of the Labels page of the Wizard.
  21. Select the color for the Predefined Template of the report. Click Next.
  22. Click Finish. The report should be available in design view.
  23. Save the report as Inventory.jsp.

    Step 2. Adding the IDAutomation Linear Barcode .jar file to Oracle Reports
     
  24. Ensure Oracle Reports is not running.
  25. Save LinearBarcode.jar to an easy-to-remember location. For example, C:\ClassPath.
  26. 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.
  27. Open Oracle Reports.
  28. Select "Open an Existing Report". Click OK.
  29. Select Inventory.rdf. Click Open.
  30. On the Program menu item, click Import Java Classes.
  31. Navigate through to COM | IDAutomation | Linear | Barcode. Click Import.
  32. Navigate through to COM | IDAutomation | Linear | Encoder | barCodeEncoder. Click Import.
  33. 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
  34. Click on the Formula Column object in the toolbar.
  35. Draw a Formula Column object in the G_Product pane of the Data Model viewer.
    Inventory Report Editor
  36. Double click the new Formula Column field to bring up the Property Inspector window.
  37. Change the Data Type property to Character.
  38. Click the formula box next to the PL/SQL Formula property in the Property Inspector. This will open the PL/SQL editor.
  39. 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.
  40. Compile the code in the PL/SQL editor to ensure there are no errors and close the PL/SQL window.
  41. Open the Page Layout for the report by double clicking the icon next to Paper Layout in Object Navigator.
  42. 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.
    page_layout_barcode.gif
  43. 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.
  44. Save the report.
  45. Select Compile | All option from the Program menu. At this point the report should be ready to preview.
  46. Select Program | Run Paper Layout from the Report Builder menu.
  47. 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

Related Documents and Keywords:

See also:

View the product index to obtain a list of all IDAutomation's products.
 

 

To sign up for monthly updates about new products or upgrades, please click here.Copyright © 2000-2007 IDAutomation.com, Inc. IDAutomation and BizFonts are registered trademarks of IDAutomation.com, Inc. All other trademarks mentioned are the property of their respective owners.

Over 70% of Fortune 100 companies use IDAutomation's products to automate their businesses.