使用C-Lodop打印控件作为Web网站/系统项目的打印部署,如果通过https协议访问需要下载安装C-Lodop扩展版(支持https,请在lodop官网下载安装)。
前端JS代码改造
假设之前已经安装部署了C-Lodop,在安装了C-Lodop扩展版之后需要改造一下原来的LodopFuncs.js文件(该文件是前端开发人员作为界面升级打印控件及全局调用的核心文件)。具体改造方法参考如下:
//====页面引用CLodop云打印必须的JS文件,用双端口(8000和18000)避免其中某个被占用:====
if (needCLodop()) {
var src1 = "http://localhost:8000/CLodopfuncs.js?priority=1";
var src2 = "http://localhost:18000/CLodopfuncs.js?priority=0";
var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
var oscript = document.createElement("script");
oscript.src = src1;
head.insertBefore(oscript, head.firstChild);
oscript = document.createElement("script");
oscript.src = src2;
head.insertBefore(oscript, head.firstChild);
CLodopIsLocal = !!((src1 + src2).match(/\/\/localho|\/\/127.0.0./i));
}
/*******之前旧版本可能是这样写的:*********/
//====页面引用CLodop云打印必须的JS文件:====
if (needCLodop()) {
var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
var oscript = document.createElement("script");
oscript.src ="http://localhost:8000/CLodopfuncs.js?priority=1";
head.insertBefore( oscript,head.firstChild );
//引用双端口(8000和18000)避免其中某个被占用:
oscript = document.createElement("script");
oscript.src ="http://localhost:18000/CLodopfuncs.js?priority=0";
head.insertBefore( oscript,head.firstChild );
};
将上面JS代码if
语句调整为以下代码:
//====页面引用CLodop云打印必须的JS文件,用双端口(8443和8444)避免其中某个被占用:====
if (needCLodop()) {
var src1 = "https://localhost:8443/CLodopfuncs.js?priority=1";
var src2 = "https://localhost:8444/CLodopfuncs.js?priority=0";
var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
var oscript = document.createElement("script");
oscript.src = src1;
head.insertBefore(oscript, head.firstChild);
oscript = document.createElement("script");
oscript.src = src2;
head.insertBefore(oscript, head.firstChild);
CLodopIsLocal = !!((src1 + src2).match(/\/\/localho|\/\/127.0.0./i));
}
注意:如果https没有完全覆盖(一般是未设置http强制跳转到https)即产品有些用户还在使用http访问,上面的代码还得改造一下: 通过JS判断URL网址采用的是什么协议。
if (needCLodop()) {
var protocol = window.location.protocol;//http、https
var src1,src2;
if(protocol == 'https:'){
src1 = "https://localhost:8443/CLodopfuncs.js?priority=1";
src2 = "https://localhost:8444/CLodopfuncs.js?priority=0";
}else{
src1 = "http://localhost:8000/CLodopfuncs.js?priority=1";
src2 = "http://localhost:18000/CLodopfuncs.js?priority=0";
}
var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
var oscript = document.createElement("script");
oscript.src = src1;
head.insertBefore(oscript, head.firstChild);
oscript = document.createElement("script");
oscript.src = src2;
head.insertBefore(oscript, head.firstChild);
CLodopIsLocal = !!((src1 + src2).match(/\/\/localho|\/\/127.0.0./i));
}
检测云打印服务是否部署成功
在浏览器地址栏里输入https://localhost:8443/
,如果能正常运行打印服务页面则部署成功,否则部署失败。


C-Lodop扩展版部署失败的可能性
- C-Lodop扩展版未安装:可以通过开始-程序查看本地安装的打印服务版本。
- 火狐浏览器不信任localhost证书:注意火狐浏览器可能不信任localhost证书,需要将地址
https://localhost:8443/
添加安全例外,具体操作步骤请看下面。
如何在火狐浏览器里管理证书?
地址栏输入about:preferences#privacy
运行后查看/管理证书,将需要添加例外的网址加入获取证书即可添加到安全例外。 操作步骤如下:


通过上图中的图文操作步骤添加安全例外就能正常运行并开启C-Lodop扩展版的打印服务,这样在https协议下就可以正常采用C-Lodop打印啦!