create or replace and compile java source named "BARCODE_HELPER" as 
/*
 * Barcode4J: Copyright 2004 Jeremias Maerki.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.image.BufferedImage;
import java.io.OutputStream;

import java.sql.*;
import oracle.sql.*;

import org.krysalis.barcode4j.impl.code39.Code39Bean;
import org.krysalis.barcode4j.impl.code128.Code128Bean;
import org.krysalis.barcode4j.impl.codabar.CodabarBean;
import org.krysalis.barcode4j.impl.code128.EAN128Bean;
import org.krysalis.barcode4j.impl.pdf417.PDF417Bean;
import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
import org.krysalis.barcode4j.impl.upcean.EAN8Bean;
import org.krysalis.barcode4j.impl.upcean.UPCABean;
import org.krysalis.barcode4j.impl.datamatrix.DataMatrixBean;
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import org.krysalis.barcode4j.tools.UnitConv;

public class BarcodeHelper {
    static int dpi = 72;
    public static void setFontPath(String fp) throws Exception {
      String sR = System.setProperty("sun.java2d.fontpath", fp);
    }
    public static void setDpi(int p_dpi) {
      dpi =p_dpi;
    }
    public int getDpi() {
     return dpi;
    }

    private static BLOB getTempBlob() throws Exception {
       Connection con = DriverManager.getConnection("jdbc:default:connection:");
       return BLOB.createTemporary(con, true, BLOB.DURATION_CALL);
    }

    public static BLOB getEAN8(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       EAN8Bean bean = new EAN8Bean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 

       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );

       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getEAN13(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       EAN13Bean bean = new EAN13Bean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 

       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );

       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getDataMatrix(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       DataMatrixBean bean = new DataMatrixBean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 

       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );
       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getUPCA(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       UPCABean bean = new UPCABean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 

       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );
       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getPDF417(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       PDF417Bean bean = new PDF417Bean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 

       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );
       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getCode39(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       Code39Bean bean = new Code39Bean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 
       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );
       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }

    public static BLOB getCode128(String barCodeNumber, String imageFormat, float unitSize) throws Exception {
       BLOB       imageBlob = getTempBlob();
       OutputStream out = imageBlob.getBinaryOutputStream(0L);

       Code128Bean bean = new Code128Bean();
       bean.setModuleWidth(UnitConv.in2mm(unitSize / dpi)); 
       BitmapCanvasProvider canvas = new BitmapCanvasProvider(
         out, imageFormat, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
       );
       bean.generateBarcode(canvas, barCodeNumber);
       canvas.finish();
       out.flush();
       out.close();
       return imageBlob;
    }
}
/
sho err

create or replace package barcode is
  procedure set_font_path(p_font_path in varchar2);
  function get_code39(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_code128(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_ean13(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_ean8(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_pdf417(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_upca(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  function get_datamatrix(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob;
  procedure set_dpi(p_dpi in number);
  function get_dpi return number;
end barcode;
/
sho err
 
create or replace package body barcode is
  procedure set_font_path(p_font_path in varchar2)
  is language java name 'BarcodeHelper.setFontPath(java.lang.String)';

  function get_code39(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getCode39(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_code128(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getCode128(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_datamatrix(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getDataMatrix(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_ean13(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getEAN13(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_ean8(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getEAN8(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_pdf417(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getPDF417(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  function get_upca(p_text in varchar2, p_imageformat in varchar2, p_unit_size in number) return blob
  is language java name 'BarcodeHelper.getUPCA(java.lang.String, java.lang.String, float) return oracle.sql.BLOB';

  procedure set_dpi(p_dpi in number)
  is language java name 'BarcodeHelper.setDpi(int)';

  function get_dpi return number
  is language java name 'BarcodeHelper.getDpi() return int';
end barcode;
/
sho err
