概述
//js代码
window.onload = function () {
xiaopiaoprint();//页面加载后打印
xiaopiaopreview();//页面加载后预览
};
var myDate = new Date();
var dayinshijian = myDate.getFullYear() + "/" + myDate.getMonth() + "/" + myDate.getDate() + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();//拼接处打印时间
var LODOP; //声明为全局变量
function xiaopiaoprint() {
Create("财务联");
LODOP.PRINT();
setTimeout(function () {
Create("客户联");
LODOP.PRINT();
setTimeout(function () {
Create("客户联");
LODOP.PRINT();
}, 5000);
}, 5000);//此处是延时打印
}
function xiaopiaopreview() {
Create("客户联");
LODOP.PREVIEW();
}
function Create(type) {//往下就不做注释了 累。。。慢慢看吧。。。
var xiaopiaotiaoxingma = document.getElementById("xiaopiaotiaoxingma").innerHTML;
var xiaopiaocon = document.getElementById("xiaopiaocon1").innerHTML;
xiaopiaocon = xiaopiaocon.replace("", dayinshijian);
if (type == "财务联") {
xiaopiaocon = xiaopiaocon + "顾客签字:=qz=**##";
}
var margintop = 10;
LODOP = getLodop();
LODOP.ADD_PRINT_IMAGE(margintop, 0, 180, 60, "");
LODOP.ADD_PRINT_TEXT(margintop, 52, 190, 0, "e奢坊洗衣凭据");
LODOP.SET_PRINT_STYLE("FontSize", 10);
LODOP.SET_PRINT_STYLE("FontName", "黑体");
LODOP.ADD_PRINT_TEXT(margintop + 70, 20, 190, 0, type + " (洗衣凭据)");
LODOP.ADD_PRINT_BARCODE(margintop + 70 + 20, 20, 190, 45, "128A", xiaopiaotiaoxingma);
LODOP.SET_PRINT_STYLE("FontSize", 7);
var xiaopiaoconarr = xiaopiaocon.split("**##");
var len = xiaopiaoconarr.length;
var i;
var eachHeight = margintop + 70 + 20 + 60;
for (i = 0; i
if (xiaopiaoconarr[i].indexOf("*|*") > 0) {//这里的主要目的是判断读取数据库的数据长度,如果长度太长,导致换行的话,就按两行或者多行显示。
var orderarr = xiaopiaoconarr[i].split("*|*");
var thisheight;
if (orderarr[0].length <= 4 && orderarr[1].length <= 3 && orderarr[2].length <= 4) {//单行 备注 这里以及后面的4、3、8等等数字是我根据我自己设置的宽度以及字体大小测试得到的,大家借鉴的时候不要生搬硬套
thisheight = 10;
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 49, thisheight, orderarr[0]);
LODOP.ADD_PRINT_TEXT(eachHeight, 50, 44, thisheight, orderarr[1]);
LODOP.ADD_PRINT_TEXT(eachHeight, 90, 49, thisheight, orderarr[2]);
LODOP.ADD_PRINT_TEXT(eachHeight, 126, 24, thisheight, orderarr[3]);
LODOP.ADD_PRINT_TEXT(eachHeight, 155, 24, thisheight, orderarr[4]);
eachHeight = eachHeight + 10;
} else if (orderarr[0].length > 4 && orderarr[0].length <= 8 && orderarr[1].length > 3 && orderarr[1].length <= 6 && orderarr[2].length > 4 && orderarr[2].length <= 8) {//两行
thisheight = 20;
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 49, thisheight, orderarr[0]);
LODOP.ADD_PRINT_TEXT(eachHeight, 50, 44, thisheight, orderarr[1]);
LODOP.ADD_PRINT_TEXT(eachHeight, 90, 49, thisheight, orderarr[2]);
LODOP.ADD_PRINT_TEXT(eachHeight, 126, 24, thisheight, orderarr[3]);
LODOP.ADD_PRINT_TEXT(eachHeight, 155, 24, thisheight, orderarr[4]);
eachHeight = eachHeight + 10;
} else {//多行
thisheight = 30;
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 49, thisheight, orderarr[0]);
LODOP.ADD_PRINT_TEXT(eachHeight, 50, 44, thisheight, orderarr[1]);
LODOP.ADD_PRINT_TEXT(eachHeight, 90, 49, thisheight, orderarr[2]);
LODOP.ADD_PRINT_TEXT(eachHeight, 126, 24, thisheight, orderarr[3]);
LODOP.ADD_PRINT_TEXT(eachHeight, 155, 24, thisheight, orderarr[4]);
eachHeight = eachHeight + 30;
}
} else if (xiaopiaoconarr[i].indexOf("=ppff=") > 0) {
var orderarr = xiaopiaoconarr[i].split("=ppff=");
if ((orderarr[0] + " ").length + orderarr[1].length >= 18) {
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[0]);
eachHeight = eachHeight + 10;
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[1]);
} else {
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[0] + " " + orderarr[1]);
}
eachHeight = eachHeight + 10;
} else if (xiaopiaoconarr[i].indexOf("=add=") > 0) {
var orderarr = xiaopiaoconarr[i].split("=add=");
if (orderarr[0].length >= 18) {
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[0].substr(0, 16));
eachHeight = eachHeight + 10;
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[0].substr(16, orderarr[0].length));
} else {
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, orderarr[0]);
}
eachHeight = eachHeight + 10;
} else if (xiaopiaoconarr[i].indexOf("##**") > 0) {
var orderarr = xiaopiaoconarr[i].split("##**");
LODOP.SET_PRINT_STYLE("FontSize", 8.5);
LODOP.ADD_PRINT_TEXT(eachHeight - 10, 100, 100, 0, orderarr[0]);
LODOP.SET_PRINT_STYLE("FontSize", 7);
eachHeight = eachHeight;
} else if (xiaopiaoconarr[i].indexOf("=qz=") > 0) {
var orderarr = xiaopiaoconarr[i].split("=qz=");
LODOP.SET_PRINT_STYLE("FontSize", 8.5);
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 100, 100, orderarr[0]);
LODOP.SET_PRINT_STYLE("FontSize", 7);
eachHeight = eachHeight + 100;
} else {
LODOP.ADD_PRINT_TEXT(eachHeight, 0, 190, 0, xiaopiaoconarr[i]);
eachHeight = eachHeight + 10;
}
}
LODOP.SET_PRINT_PAGESIZE(0, 580, (eachHeight + 30) * 2.6458, "");
i = null;
}
其实也可以用Lodop的 ADD_PRINT_HTM方法来打印,但是 ADD_PRINT_HTM方法貌似不能调整字体大小,所以我只能用拼接拆分字符串的方式一行一行的打印。如果有高手知道怎么用 ADD_PRINT_HTM 方法来调整字体大小的方法,还望指点一下小生。
代码乱七八糟,望大牛们多多指点。
Lodop免费版直接打印的时候会带水印。暂时没找到去掉的办法。
最后
以上就是暴躁毛巾为你收集整理的php lodop,web页面通过JS调用Lodop控件打印小票代码的全部内容,希望文章能够帮你解决php lodop,web页面通过JS调用Lodop控件打印小票代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复