做这个的例子太少,我把我做的示例亮出来
一.先说说需要的版本
1.我用的浏览器只有ie:
火狐只支持52版本以下,并且是java7、java8。chrome不支持
2.applet客户端打印,需要java6:
亲自测试,java6需要一些提示是否运行,等都同意后,打印时不用再提示。
在java7、8,我自己测试控制面板里面没有低级,只有高级和超高级,不管什么时候打印,它都会提示是否同意
所以,我最终还是选择了在applet里放入jre6
二.applet的打印代码
1.html,在ie下才可运行
因为执行的时候,需要检查有没有jre6、请求/接受路径、一些传递的参数,运行的class、需要的jar,代码如下:
function is_ie(json, print_type) { //){ //项目的根路径 var req_path = "http://localhost:8080"; //打印机名 var print_name = "Deli DL-888C"; var str = "JRPrinterApplet"; var archive = 'jbarcodebean-1.2.0.jar,json-20160810.jar,print.jar'; var codebase = '/applets' var file = '/applets/jre-6u45-windows-i586.exe'; var scriptable = false; var type = 'application/x-java-applet;version=1.6.0'; var clsid = ""; if (isFamilyVersionSupported()) { clsid = "clsid:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"; } else { clsid = "clsid:CAFEEFAC-0016-0000-0008-ABCDEFFEDCBA"; } var write = '' + //'<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width = "0" height = "0" codebase="'+file+'" mayscript>' + '<object classid="' + clsid + '" width = "0" height = "0" codebase="' + file + '" mayscript>' + '<param name = "code" value = "' + str + '.class" >' + '<param name = "codebase" value = "' + codebase + '" >' + '<param name = "archive" value = "' + archive + '" >' + '<param value="' + type + '">' + '<param value="' + scriptable + '">' + '<param name = "print_type" value ="' + print_type + '">' + '<param name = "print_name" value ="' + print_name + '">' + '<param name = "req_path" value ="' + req_path + '">' + '<param name = "json" value =\'' + json + '\'>' + '<comment>' + '<embed type="' + type + '" code="' + str + '.class" java_codebase="' + codebase + '" archive="' + archive + '" scriptable=' + scriptable + ' pluginspage="' + file + '" >' + '<noembed></noembed>' + '</embed>' + '</comment>' + '</object>'; $("#objectDiv").html(write) if(print_type=='login_test'){ } }