http://blog.sina.com.cn/s/blog_6543cca50101euon.html
extjs由于是基于JS语言,其打印是可以按照一般的WEB打印方式来进行。笔者在网络上发现第三方打印插件Lodop(详见地址:http://mtsoftware.v053.gokao.net/index.html),因为这个插件可以实现多种浏览器(如:IE FF 谷歌),笔者讲究了一下,简单介绍如下:
1:引入Lodop
在页面的head位置引入
在JS中调用控件前用如下方式获得对象:
var LODOP=getLodop(document.getElementByIdx_x_x('LODOP_OB'),document.getElementByIdx_x_x('LODOP_EM'));
(代码见后面)
2:简单的使用实例
<script language="javascript" type="text/javascript">
Ext.onReady(function(){
var win;
var LODOP;
if(!win){
win = new Ext.Window({
title:'LODOP打印控件测试',
width:600,
height:450,
closeAction:'close',
plain: true,
autoLoad:{url:'a.asp',scripts:true},
buttons: [{
text:"测试",
handler: CheckIsInstall
},
{
text:'打印预览',
handler: prn1_preview
},{
text: 'Close',
handler: function(){
win.close();
}
}]
});
}
win.show(this);
function prn1_preview() {
CreateOneFormPage();
LODOP.PREVIEW();
};
function CreateOneFormPage()
{
LODOP=getLodop(document.getElementByIdx_x('LODOP_OB'),document.getElementByIdx_x('LODOP_EM'));
LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_表单一");
LODOP.SET_PRINT_STYLE("FontSize",18);
LODOP.SET_PRINT_STYLE("Bold",1);
LODOP.ADD_PRINT_HTM(18,20,350,600,document.getElementByIdx_x("form2").innerHTML);
};
function CheckIsInstall()
{
try{
var LODOP=getLodop(document.getElementByIdx_x('LODOP_OB'),document.getElementByIdx_x('LODOP_EM'));
if ((LODOP!=null)&&(typeof(LODOP.VERSION)!="undefined"))
Ext.MessageBox.alert("提示","本机已成功安装过Lodop控件!\n 版本号:"+LODOP.VERSION);
}catch(err)
{
//alert("Error:本机未安装或需要升级!");
}
}
}
)
</script>
--------------------
LodopFuncs.js 代码
function getLodop(oOBJECT, oEMBED) {
///
var strHtmInstall = "
打印控件未安装!点击这里执行安装,安装后请刷新页面或重新进入。";
var strHtmUpdate = "
打印控件需要升级!点击这里执行升级,升级后请重新进入。";
var strHtm64_Install = "
打印控件未安装!点击这里执行安装,安装后请刷新页面或重新进入。";
var strHtm64_Update = "
打印控件需要升级!点击这里执行升级,升级后请重新进入。";
var strHtmFireFox = "
注意:
1:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它。";
var LODOP = oEMBED;
try {
if (navigator.appVersion.indexOf("MSIE") >= 0) LODOP = oOBJECT;
if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
if (navigator.userAgent.indexOf('Firefox') >= 0) document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
if (navigator.userAgent.indexOf('Win64') >= 0) {
if (navigator.appVersion.indexOf("MSIE") >= 0) document.write(strHtm64_Install);
else document.documentElement.innerHTML = strHtm64_Install + document.documentElement.innerHTML;
} else {
if (navigator.appVersion.indexOf("MSIE") >= 0) document.write(strHtmInstall);
else document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
}
return LODOP;
} else if (LODOP.VERSION < "6.1.3.7") {
if (navigator.userAgent.indexOf('Win64') >= 0) {
if (navigator.appVersion.indexOf("MSIE") >= 0) document.write(strHtm64_Update);
else document.documentElement.innerHTML = strHtm64_Update + document.documentElement.innerHTML;
} else {
if (navigator.appVersion.indexOf("MSIE") >= 0) document.write(strHtmUpdate);
else document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
}
return LODOP;
}
//*****如下空白位置适合调用统一功能:*********
//*******************************************
return LODOP;
} catch(err) {
if (navigator.userAgent.indexOf('Win64') >= 0)
document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML;
else document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
return LODOP;
}
}