EBS條碼列印

來源:互聯網
上載者:User

標籤:style   blog   http   java   使用   strong   io   檔案   

Oracle  提供兩種方式實現 128 碼的編碼
第一種方式是使用 Reports Builder 實現對 128 碼編碼, 在 Metalink 305090.1[1]  有
比較詳盡的描述,其中的 IDAUTOMATION.PLL 中包含方法 Code128A, Code128B
及 Code128C 分別實現了 A,B,C 類 128 碼的編碼。具體的實現方法請參照 MetaLink
305090.1  。
第二種方法是通過 XML Publisher 實現 128 碼的編碼。因為超過 128  的 ASCII 碼對
應的特殊字元在 PL/SQL 中無法顯示,但是在 128 碼中使用這些字元作為 128 碼的
起始終止位以及校正位,編碼的過程放在 PL/SQL 端實現並產生 XML 資料結合模板
產生條碼較難實現。改變思路,我們把編碼過程放在 JAVA 類中,通過在結合模板
時調用產生 128 碼就可以實現條碼的產生和列印。在《Oracle XML Publisher
Administration and Developer‘s Guide》中 Advanced Barcode Font Formatting
Implementation  中提供了這種方法的實現。在 Metalink 782809.1[2]中提供 JAVA 版
128 碼編碼實作類別(BarcodeUtil.java)的下載,以及測試使用相應的模板檔案

(TestBarcodeUtil.rtf)


以下內容以字型IDAutomationC128M 為示範


一.WINDOWS本地字型配置

下載條碼字型,複製到系統字型檔夾裡,自動安裝


二,上傳java到伺服器

1.查看java裡路徑  例如:package oracle.apps.xdo.template.rtf.util.barcoder;

上傳java檔案BarcodeUtil.java到目錄  $JAVA_TOP/oracle/apps/xdo/template/rtf/util/barcoder 沒有建立


編譯java檔案

java檔案如下

/*    Code extracted from     Oracle?XML Publisher     Core Components Guide    Release 10.1.3.3    Pages 8-60 to 8-64*/package oracle.apps.xdo.template.rtf.util.barcoder;import java.util.Hashtable;import java.lang.reflect.Method;import oracle.apps.xdo.template.rtf.util.XDOBarcodeEncoder;import oracle.apps.xdo.common.log.Logger;// This class name will be used in the register vendor// field in the template.public class BarcodeUtil implements XDOBarcodeEncoder// The class implements the XDOBarcodeEncoder interface{    // This is the barcode vendor id that is used in the    // register vendor field and format-barcode fields    public static final String BARCODE_VENDOR_ID = "XMLPBarVendor";        // The hashtable is used to store references to    // the encoding methods    public static final Hashtable ENCODERS = new Hashtable(10);        // The BarcodeUtil class needs to be instantiated    public static final BarcodeUtil mUtility = new BarcodeUtil();        // This is the main code that is executed in the class,    // it is loading the methods for the encoding into the hashtable.    // In this case we are loading the three code128 encoding    // methods we have created.    static {        try {            Class[] clazz = new Class[] { "".getClass() };            ENCODERS.put("code128a",mUtility.getClass().getMethod("code128a", clazz));            ENCODERS.put("code128b",mUtility.getClass().getMethod("code128b", clazz));            ENCODERS.put("code128c",mUtility.getClass().getMethod("code128c", clazz));        } catch (Exception e) {            // This is using the XML Publisher logging class to push            // errors to the XMLP log file.            Logger.log(e,5);            }    }    // The getVendorID method is called from the template layer    // at runtime to ensure the correct encoding method are used    public final String getVendorID()    {        return BARCODE_VENDOR_ID;    }        //The isSupported method is called to ensure that the    // encoding method called from the template is actually    // present in this class.    // If not then XMLP will report this in the log.    public final boolean isSupported(String s)    {        if(s != null)        return ENCODERS.containsKey(s.trim().toLowerCase());        else        return false;    }        // The encode method is called to then call the appropriate    // encoding method, in this example the code128a/b/c methods.    public final String encode(String s, String s1)    {        if(s != null && s1 != null)        {            try             {                Method method = (Method)ENCODERS.get(s1.trim().toLowerCase());                if(method != null)                    return (String)method.invoke(this, new Object[] { s });                else                    return s;            }            catch(Exception exception)            {                Logger.log(exception,5);            }            return s;        } else {            return s;        }    }        /** This is the complete method for Code128a */    public static final String code128a( String DataToEncode )    {        char C128_Start = (char)203;        char C128_Stop = (char)206;        String Printable_string = "";        char CurrentChar;        int CurrentValue=0;        int weightedTotal=0;        int CheckDigitValue=0;        char C128_CheckDigit='w';        DataToEncode = DataToEncode.trim();        weightedTotal = ((int)C128_Start) - 100;        for( int i = 1; i <= DataToEncode.length(); i++ )        {            //get the value of each character            CurrentChar = DataToEncode.charAt(i-1);            if( ((int)CurrentChar) < 135 )                CurrentValue = ((int)CurrentChar) - 32;            if( ((int)CurrentChar) > 134 )                CurrentValue = ((int)CurrentChar) - 100;                            CurrentValue = CurrentValue * i;            weightedTotal = weightedTotal + CurrentValue;        }                //divide the WeightedTotal by 103 and get the remainder,        //this is the CheckDigitValue        CheckDigitValue = weightedTotal % 103;        if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )            C128_CheckDigit = (char)(CheckDigitValue + 32);        if( CheckDigitValue > 94 )            C128_CheckDigit = (char)(CheckDigitValue + 100);        if( CheckDigitValue == 0 ){            C128_CheckDigit = (char)194;        }                Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";        return Printable_string;    }    /** This is the complete method for Code128b ***/    public static final String code128b( String DataToEncode )    {        char C128_Start = (char)204;        char C128_Stop = (char)206;        String Printable_string = "";        char CurrentChar;        int CurrentValue=0;        int weightedTotal=0;        int CheckDigitValue=0;        char C128_CheckDigit='w';        DataToEncode = DataToEncode.trim();        weightedTotal = ((int)C128_Start) - 100;                for( int i = 1; i <= DataToEncode.length(); i++ )        {            //get the value of each character            CurrentChar = DataToEncode.charAt(i-1);            if( ((int)CurrentChar) < 135 )                CurrentValue = ((int)CurrentChar) - 32;            if( ((int)CurrentChar) > 134 )                CurrentValue = ((int)CurrentChar) - 100;                            CurrentValue = CurrentValue * i;            weightedTotal = weightedTotal + CurrentValue;        }                //divide the WeightedTotal by 103 and get the remainder,        //this is the CheckDigitValue        CheckDigitValue = weightedTotal % 103;        if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )            C128_CheckDigit = (char)(CheckDigitValue + 32);        if( CheckDigitValue > 94 )            C128_CheckDigit = (char)(CheckDigitValue + 100);        if( CheckDigitValue == 0 ){            C128_CheckDigit = (char)194;        }                Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";        return Printable_string;    }    /** This is the complete method for Code128c **/    public static final String code128c( String s )    {        char C128_Start = (char)205;        char C128_Stop = (char)206;        String Printable_string = "";        String DataToPrint = "";        String OnlyCorrectData = "";        int i=1;        int CurrentChar=0;        int CurrentValue=0;        int weightedTotal=0;        int CheckDigitValue=0;        char C128_CheckDigit='w';        DataToPrint = "";        s = s.trim();                for(i = 1; i <= s.length(); i++ )        {            //Add only numbers to OnlyCorrectData string            CurrentChar = (int)s.charAt(i-1);            if((CurrentChar < 58) && (CurrentChar > 47))            {                OnlyCorrectData = OnlyCorrectData + (char)s.charAt(i-1);            }        }        s = OnlyCorrectData;                //Check for an even number of digits, add 0 if not even        if( (s.length() % 2) == 1 )        {            s = "0" + s;        }                //<<<< Calculate Modulo 103 Check Digit and generate        // DataToPrint >>>>//Set WeightedTotal to the Code 128 value of        // the start character        weightedTotal = ((int)C128_Start) - 100;        int WeightValue = 1;        for( i = 1; i <= s.length(); i += 2 )        {            //Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)             //And assign the ASCII values to DataToPrint            CurrentChar = ((((int)s.charAt(i-1))-48)*10) + (((int)s.charAt(i))-48);                        if((CurrentChar < 95) && (CurrentChar > 0))                DataToPrint = DataToPrint + (char)(CurrentChar + 32);            if( CurrentChar > 94 )                DataToPrint = DataToPrint + (char)(CurrentChar + 100);            if( CurrentChar == 0)                DataToPrint = DataToPrint + (char)194;                            //multiply by the weighting character            //add the values together to get the weighted total            weightedTotal = weightedTotal + (CurrentChar * WeightValue);            WeightValue = WeightValue + 1;        }                //divide the WeightedTotal by 103 and get the remainder,        //this is the CheckDigitValue        CheckDigitValue = weightedTotal % 103;                if((CheckDigitValue < 95) && (CheckDigitValue > 0))            C128_CheckDigit = (char)(CheckDigitValue + 32);        if( CheckDigitValue > 94 )            C128_CheckDigit = (char)(CheckDigitValue + 100);        if( CheckDigitValue == 0 ){            C128_CheckDigit = (char)194;        }                Printable_string = C128_Start + DataToPrint + C128_CheckDigit + C128_Stop + " ";        Logger.log(Printable_string,5);        return Printable_string;    }} /*End BarcodeUtil class */

三,產生xml資料來源

舉例如下

<?xml version="1.0" encoding="UTF-8"?><RECEIPT_APPLIED><LINES><ITEM_CODE>F4990010010</ITEM_CODE><ITEM_NAME><![CDATA[財稅通軟體 V1.0]]></ITEM_NAME><BARCODE>912014266</BARCODE></LINES><LINES><ITEM_CODE>F4990010010</ITEM_CODE><ITEM_NAME><![CDATA[財稅通軟體 V1.0]]></ITEM_NAME><BARCODE>912014265</BARCODE></LINES></RECEIPT_APPLIED>

四.根據資料來源製作模板

說明:REG裡面   <?register-barcode-vendor:‘oracle.apps.xdo.template.rtf.util.barcoder.BarcodeUtil‘;‘XMLPBarVendor‘?> 註冊條碼編碼類別

           條碼裡        <?format-barcode:BARCODE;‘Code128a‘;‘XMLPBarVendor‘?>    資料格式化


五.註冊資料來源,模板

略


六.上傳字型

在XML Publisher Administrator職責下,首先上傳字型檔



七.配置字型映射

在XML Publisher Administrator職責下,定義字型轉換映射集

由於我們的模板使用的是RTF格式的,因此Type需要選擇FO To PDF


在XML Publisher Administrator職責下,定義字型轉換映射關係

輸入Font Family,這個值可以開啟字型檔來查看

根據模板中使用字型的情況來選擇Style和Weight

如果需要根據Locale來決定使用字型映射,則填入Language和Territory,不填代表所有語音環境下都適用




八,模板和字型映射關聯

定義好字型映射之後,修改BIP模板檔案的配置

查詢出BIP模板定義後,點擊右上方的 Edit Configuration 按鈕


尋找模板

展開FO Processing部分,設定Font mapping set為上面定義好的字型映射集


最後提交請求,查看輸出




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.