打印发票使用lodop控件
下载LodopFuncs.js
下载安装lodop插件install_lodop32.exe
html代码如下:
<html>
<head>
<script src="LodopFuncs.js" type="text/javascript"></script>
<object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width="0" height="0">
<embed id="LODOP_EM" type="application/x-print-lodop" width="0" height="0" pluginspage="install_lodop32.exe"></embed>
</object>
<script language="javascript" type="text/javascript">
var LODOP; //声明为全局变量
function myPreview() {
CreatePrintPage();
LODOP.PREVIEW(); //打印预览
};
function CreatePrintPage(){
LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
LODOP.SET_PRINT_PAGESIZE(1, "2500","1500","CreateCustomPage");
var goTop = 0; //0
var goLeft = -30;//-80
LODOP.ADD_PRINT_TEXT(50 + goTop, 440+goLeft, 360, 200, "XXXX公司收款收据");
LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
LODOP.ADD_PRINT_TEXT(70 + goTop, 740+goLeft, 360, 200, "第 次打印");
LODOP.ADD_PRINT_TEXT(100 + goTop, 200+goLeft, 160, 20, "收据号:");//用户名称
LODOP.ADD_PRINT_TEXT(100 + goTop, 260+goLeft, 160, 20, "dsfa2223");//用户名称
LODOP.ADD_PRINT_TEXT(100 + goTop, 430+goLeft, 160, 20, "收款日期:");//号码
LODOP.ADD_PRINT_TEXT(100 + goTop, 630+goLeft, 180, 20, "2015年4月16日");//流水号
LODOP.ADD_PRINT_LINE(120 + goTop, 160+goLeft,120 + goTop,830+goLeft,0,1);
LODOP.ADD_PRINT_TEXT(130 + goTop, 200+goLeft, 160, 20, "客户名称");//用户名称
LODOP.ADD_PRINT_TEXT(130 + goTop, 280+goLeft, 160, 20, "张东");
LODOP.ADD_PRINT_LINE(150 + goTop, 160+goLeft,150 + goTop,830+goLeft,0,1);
//左边第二条竖线
LODOP.ADD_PRINT_LINE(120 + goTop, 260+goLeft,350 + goTop,260+goLeft,0,1);
LODOP.ADD_PRINT_LINE(350 + goTop, 160+goLeft,350 + goTop,830+goLeft,0,1);
LODOP.ADD_PRINT_TEXT(130 + goTop, 660+goLeft,180,20,"号码");
LODOP.ADD_PRINT_TEXT(130 + goTop, 720+goLeft,180,20,"111111111");
LODOP.ADD_PRINT_LINE(380 + goTop, 160+goLeft,380 + goTop,830+goLeft,0,1);
LODOP.ADD_PRINT_TEXT(250 + goTop, 200+goLeft, 160, 20, "收费项目");//
LODOP.ADD_PRINT_TEXT(360 + goTop, 200+goLeft,180,20,"合计金额(大写)");
LODOP.ADD_PRINT_TEXT(360 + goTop, 320+goLeft,180,20,"壹仟贰佰玖拾");
LODOP.ADD_PRINT_LINE(120 + goTop, 650+goLeft,150 + goTop,650+goLeft,0,1);
LODOP.ADD_PRINT_LINE(120 + goTop, 700+goLeft,150 + goTop,700+goLeft,0,1);
LODOP.ADD_PRINT_LINE(350 + goTop, 650+goLeft,380 + goTop,650+goLeft,0,1);
LODOP.ADD_PRINT_TEXT(360 + goTop, 660+goLeft,180,20,"合计:");
LODOP.ADD_PRINT_TEXT(360 + goTop, 700+goLeft,180,20,"¥1290");
LODOP.ADD_PRINT_TEXT(390 + goTop, 200+goLeft,180,20,"收款人:");
LODOP.ADD_PRINT_TEXT(390 + goTop, 260+goLeft,180,20,"张三");
LODOP.ADD_PRINT_IMAGE(240+ goTop, 700+goLeft,130,130,"<img src='print_6.png' width='105px' height='105px'/>");
LODOP.ADD_PRINT_IMAGE(50 + goTop, 200+goLeft, 120, 120, "<img src='print_7.png' width='80px' height='40px' />");
//左边最外一条竖线
LODOP.ADD_PRINT_LINE(120 + goTop, 160+goLeft,380 + goTop,160+goLeft,0,1);
//右边最外一条竖线
LODOP.ADD_PRINT_LINE(120 + goTop, 830+goLeft,380 + goTop,830+goLeft,0,1);
var firstHigh = 170 + goTop;
var rowHigh2 = 18;
var currHigh = "";
var array = "过户费|1|6.0元|¥6.0|##".split("##");
for ( var i = 0; i < array.length; i++) {
var row = array[i];
if (row != null && row != "") {
var item = row.split("|");
currHigh = firstHigh + i * rowHigh2;
//账目项名称
if (item[0] != null && item[0] != "") {
LODOP.ADD_PRINT_TEXT(currHigh, 380+goLeft, 260, rowHigh2 - 2, item[0]);
}
//金额
if (item[3] != null && item[3] != "") {
LODOP.ADD_PRINT_TEXT(currHigh, 650+goLeft, 70, rowHigh2 - 2, item[3]);
}
}
}
var orgArray = "951##2015.04.16.06.35##开发区营业厅##".split("##");
LODOP.ADD_PRINT_TEXT(currHigh+18, 680+goLeft, 70, rowHigh2 - 2, orgArray[0]);
LODOP.ADD_PRINT_TEXT(currHigh+36, 610+goLeft, 120, rowHigh2 - 2, orgArray[1]);
LODOP.ADD_PRINT_TEXT(currHigh+54, 620+goLeft, 120, rowHigh2 - 2, orgArray[2]);
};
</script>
</head>
<body>
<a href="javascript:myPreview()"><b>打印预览</b></a>
</body>
</html>
打印预览效果: