![]() ![]() |
Creating Barcodes in Oracle 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. Compatibility
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.
Tutorial on how to access the JAR Properties in the API. Step 1. Creating a report using a comma-delimited data source
Step 2. Adding the IDAutomation Barcode Java Component to Oracle Reports
Symbology Code ExampleLinear 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 LinearBarCode.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 and Keywords:
View the
product index to obtain a list of all IDAutomation's
products. |
©Copyright 2019
IDAutomation.com, All Rights Reserved.
Legal
Notices. Barcode Fonts | Components | Scanners | Support | Contact Us |
|
![]() ![]() ![]() ![]() ![]() Over 70% of Fortune 100 companies use IDAutomation's products to automate their businesses. |