EBS条形码打印

来源:互联网 发布:php学生管理系统全套 编辑:程序博客网 时间:2024/06/11 14:25
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文件如下

[java] view plaincopy在CODE上查看代码片派生到我的代码片
  1. /* 
  2.     Code extracted from  
  3.     Oracle?XML Publisher  
  4.     Core Components Guide 
  5.     Release 10.1.3.3 
  6.     Pages 8-60 to 8-64 
  7. */  
  8.   
  9. package oracle.apps.xdo.template.rtf.util.barcoder;  
  10.   
  11. import java.util.Hashtable;  
  12. import java.lang.reflect.Method;  
  13. import oracle.apps.xdo.template.rtf.util.XDOBarcodeEncoder;  
  14. import oracle.apps.xdo.common.log.Logger;  
  15.   
  16. // This class name will be used in the register vendor  
  17. // field in the template.  
  18.   
  19. public class BarcodeUtil implements XDOBarcodeEncoder  
  20. // The class implements the XDOBarcodeEncoder interface  
  21. {  
  22.     // This is the barcode vendor id that is used in the  
  23.     // register vendor field and format-barcode fields  
  24.     public static final String BARCODE_VENDOR_ID = "XMLPBarVendor";  
  25.       
  26.     // The hashtable is used to store references to  
  27.     // the encoding methods  
  28.     public static final Hashtable ENCODERS = new Hashtable(10);  
  29.       
  30.     // The BarcodeUtil class needs to be instantiated  
  31.     public static final BarcodeUtil mUtility = new BarcodeUtil();  
  32.       
  33.     // This is the main code that is executed in the class,  
  34.     // it is loading the methods for the encoding into the hashtable.  
  35.     // In this case we are loading the three code128 encoding  
  36.     // methods we have created.  
  37.     static {  
  38.         try {  
  39.             Class[] clazz = new Class[] { "".getClass() };  
  40.             ENCODERS.put("code128a",mUtility.getClass().getMethod("code128a", clazz));  
  41.             ENCODERS.put("code128b",mUtility.getClass().getMethod("code128b", clazz));  
  42.             ENCODERS.put("code128c",mUtility.getClass().getMethod("code128c", clazz));  
  43.         } catch (Exception e) {  
  44.             // This is using the XML Publisher logging class to push  
  45.             // errors to the XMLP log file.  
  46.             Logger.log(e,5);  
  47.             }  
  48.     }  
  49.   
  50.     // The getVendorID method is called from the template layer  
  51.     // at runtime to ensure the correct encoding method are used  
  52.     public final String getVendorID()  
  53.     {  
  54.         return BARCODE_VENDOR_ID;  
  55.     }  
  56.       
  57.     //The isSupported method is called to ensure that the  
  58.     // encoding method called from the template is actually  
  59.     // present in this class.  
  60.     // If not then XMLP will report this in the log.  
  61.     public final boolean isSupported(String s)  
  62.     {  
  63.         if(s != null)  
  64.         return ENCODERS.containsKey(s.trim().toLowerCase());  
  65.         else  
  66.         return false;  
  67.     }  
  68.       
  69.     // The encode method is called to then call the appropriate  
  70.     // encoding method, in this example the code128a/b/c methods.  
  71.     public final String encode(String s, String s1)  
  72.     {  
  73.         if(s != null && s1 != null)  
  74.         {  
  75.             try   
  76.             {  
  77.                 Method method = (Method)ENCODERS.get(s1.trim().toLowerCase());  
  78.                 if(method != null)  
  79.                     return (String)method.invoke(thisnew Object[] { s });  
  80.                 else  
  81.                     return s;  
  82.             }  
  83.             catch(Exception exception)  
  84.             {  
  85.                 Logger.log(exception,5);  
  86.             }  
  87.             return s;  
  88.         } else {  
  89.             return s;  
  90.         }  
  91.     }  
  92.       
  93.     /** This is the complete method for Code128a */  
  94.     public static final String code128a( String DataToEncode )  
  95.     {  
  96.         char C128_Start = (char)203;  
  97.         char C128_Stop = (char)206;  
  98.         String Printable_string = "";  
  99.         char CurrentChar;  
  100.         int CurrentValue=0;  
  101.         int weightedTotal=0;  
  102.         int CheckDigitValue=0;  
  103.         char C128_CheckDigit='w';  
  104.         DataToEncode = DataToEncode.trim();  
  105.   
  106.         weightedTotal = ((int)C128_Start) - 100;  
  107.         forint i = 1; i <= DataToEncode.length(); i++ )  
  108.         {  
  109.             //get the value of each character  
  110.             CurrentChar = DataToEncode.charAt(i-1);  
  111.             if( ((int)CurrentChar) < 135 )  
  112.                 CurrentValue = ((int)CurrentChar) - 32;  
  113.             if( ((int)CurrentChar) > 134 )  
  114.                 CurrentValue = ((int)CurrentChar) - 100;  
  115.                   
  116.             CurrentValue = CurrentValue * i;  
  117.             weightedTotal = weightedTotal + CurrentValue;  
  118.         }  
  119.           
  120.         //divide the WeightedTotal by 103 and get the remainder,  
  121.         //this is the CheckDigitValue  
  122.         CheckDigitValue = weightedTotal % 103;  
  123.         if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )  
  124.             C128_CheckDigit = (char)(CheckDigitValue + 32);  
  125.         if( CheckDigitValue > 94 )  
  126.             C128_CheckDigit = (char)(CheckDigitValue + 100);  
  127.         if( CheckDigitValue == 0 ){  
  128.             C128_CheckDigit = (char)194;  
  129.         }  
  130.           
  131.         Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";  
  132.         return Printable_string;  
  133.     }  
  134.   
  135.   
  136.     /** This is the complete method for Code128b ***/  
  137.     public static final String code128b( String DataToEncode )  
  138.     {  
  139.         char C128_Start = (char)204;  
  140.         char C128_Stop = (char)206;  
  141.         String Printable_string = "";  
  142.         char CurrentChar;  
  143.         int CurrentValue=0;  
  144.         int weightedTotal=0;  
  145.         int CheckDigitValue=0;  
  146.         char C128_CheckDigit='w';  
  147.         DataToEncode = DataToEncode.trim();  
  148.         weightedTotal = ((int)C128_Start) - 100;  
  149.           
  150.         forint i = 1; i <= DataToEncode.length(); i++ )  
  151.         {  
  152.             //get the value of each character  
  153.             CurrentChar = DataToEncode.charAt(i-1);  
  154.             if( ((int)CurrentChar) < 135 )  
  155.                 CurrentValue = ((int)CurrentChar) - 32;  
  156.             if( ((int)CurrentChar) > 134 )  
  157.                 CurrentValue = ((int)CurrentChar) - 100;  
  158.                   
  159.             CurrentValue = CurrentValue * i;  
  160.             weightedTotal = weightedTotal + CurrentValue;  
  161.         }  
  162.           
  163.         //divide the WeightedTotal by 103 and get the remainder,  
  164.         //this is the CheckDigitValue  
  165.         CheckDigitValue = weightedTotal % 103;  
  166.         if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )  
  167.             C128_CheckDigit = (char)(CheckDigitValue + 32);  
  168.         if( CheckDigitValue > 94 )  
  169.             C128_CheckDigit = (char)(CheckDigitValue + 100);  
  170.         if( CheckDigitValue == 0 ){  
  171.             C128_CheckDigit = (char)194;  
  172.         }  
  173.           
  174.         Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";  
  175.         return Printable_string;  
  176.     }  
  177.   
  178.   
  179.     /** This is the complete method for Code128c **/  
  180.     public static final String code128c( String s )  
  181.     {  
  182.         char C128_Start = (char)205;  
  183.         char C128_Stop = (char)206;  
  184.         String Printable_string = "";  
  185.         String DataToPrint = "";  
  186.         String OnlyCorrectData = "";  
  187.         int i=1;  
  188.         int CurrentChar=0;  
  189.         int CurrentValue=0;  
  190.         int weightedTotal=0;  
  191.         int CheckDigitValue=0;  
  192.         char C128_CheckDigit='w';  
  193.         DataToPrint = "";  
  194.         s = s.trim();  
  195.           
  196.         for(i = 1; i <= s.length(); i++ )  
  197.         {  
  198.             //Add only numbers to OnlyCorrectData string  
  199.             CurrentChar = (int)s.charAt(i-1);  
  200.             if((CurrentChar < 58) && (CurrentChar > 47))  
  201.             {  
  202.                 OnlyCorrectData = OnlyCorrectData + (char)s.charAt(i-1);  
  203.             }  
  204.         }  
  205.         s = OnlyCorrectData;  
  206.           
  207.         //Check for an even number of digits, add 0 if not even  
  208.         if( (s.length() % 2) == 1 )  
  209.         {  
  210.             s = "0" + s;  
  211.         }  
  212.           
  213.         //<<<< Calculate Modulo 103 Check Digit and generate  
  214.         // DataToPrint >>>>//Set WeightedTotal to the Code 128 value of  
  215.         // the start character  
  216.         weightedTotal = ((int)C128_Start) - 100;  
  217.         int WeightValue = 1;  
  218.         for( i = 1; i <= s.length(); i += 2 )  
  219.         {  
  220.             //Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)   
  221.             //And assign the ASCII values to DataToPrint  
  222.             CurrentChar = ((((int)s.charAt(i-1))-48)*10) + (((int)s.charAt(i))-48);  
  223.               
  224.             if((CurrentChar < 95) && (CurrentChar > 0))  
  225.                 DataToPrint = DataToPrint + (char)(CurrentChar + 32);  
  226.             if( CurrentChar > 94 )  
  227.                 DataToPrint = DataToPrint + (char)(CurrentChar + 100);  
  228.             if( CurrentChar == 0)  
  229.                 DataToPrint = DataToPrint + (char)194;  
  230.                   
  231.             //multiply by the weighting character  
  232.             //add the values together to get the weighted total  
  233.             weightedTotal = weightedTotal + (CurrentChar * WeightValue);  
  234.             WeightValue = WeightValue + 1;  
  235.         }  
  236.           
  237.         //divide the WeightedTotal by 103 and get the remainder,  
  238.         //this is the CheckDigitValue  
  239.         CheckDigitValue = weightedTotal % 103;  
  240.           
  241.         if((CheckDigitValue < 95) && (CheckDigitValue > 0))  
  242.             C128_CheckDigit = (char)(CheckDigitValue + 32);  
  243.         if( CheckDigitValue > 94 )  
  244.             C128_CheckDigit = (char)(CheckDigitValue + 100);  
  245.         if( CheckDigitValue == 0 ){  
  246.             C128_CheckDigit = (char)194;  
  247.         }  
  248.           
  249.         Printable_string = C128_Start + DataToPrint + C128_CheckDigit + C128_Stop + " ";  
  250.         Logger.log(Printable_string,5);  
  251.         return Printable_string;  
  252.     }  
  253. /*End BarcodeUtil class */  

三,生成xml数据源

举例如下

[sql] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <RECEIPT_APPLIED>  
  3. <LINES>  
  4. <ITEM_CODE>F4990010010</ITEM_CODE>  
  5. <ITEM_NAME><![CDATA[财税通软件 V1.0]]></ITEM_NAME>  
  6. <BARCODE>912014266</BARCODE>  
  7. </LINES>  
  8. <LINES>  
  9. <ITEM_CODE>F4990010010</ITEM_CODE>  
  10. <ITEM_NAME><![CDATA[财税通软件 V1.0]]></ITEM_NAME>  
  11. <BARCODE>912014265</BARCODE>  
  12. </LINES>  
  13. </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为上面定义好的字体映射集


最后提交请求,查看输出

0 0