当前位置: 代码迷 >> 综合 >> lodop-web打印控件
  详细解决方案

lodop-web打印控件

热度:81   发布时间:2024-01-18 22:42:39.0

一、概述

Lodop是一款专业的WEB打印控件,其设计目标是简单易用、功能足够强大,开创WEB打印开发的新局面。

Lodop设计者对WEB下的打印开发任务进行了分类汇总,高度抽象,设计出仅用几个功能函数,就可实现复杂的打印任务,尽量减少使用者的知识累赘。控件发布包有3个系统文件组成,全部功能用几个控件参数和2组功能函数来实现。

尽管我们有个理想化的目标,那就是您不用详细了解这些参数或函数,仅仅看懂几个样例文件就能很轻松地开始使用本控件,为此Lodop提供了一个足够完善的设计界面,用它可以实现大多数打印开发任务,但事实上了解这些参数和函数总还是有好处的,特别是当您的开发任务很复杂时,这就是本文目的,但愿本文档足够详细且简单明了。

如果此前曾看过lodop的入门样例程序,本文会更容易理解!

二、系统文件

Lodop发布包内主要有如下几个文件:

install_lodop.exe

该文件是控件安装和升级的主文件,提供给用户或开发者下载安装,如果不特意拦截一般都能100%安装,对“网页插件安装难”有一定改善。如果将其复制或改名为uninstall_lodop.exe (名前加un)就可用其卸载控件。

Lodop安装后,在操作系统目录WINDOWS\system32下会安装两个实体文件:CAOSOFT_WEB_PRINT_LODOP.OCXNPCAOSOFT_WEB_PRINT_lodop.dll,前一个文件是OCX文件,后者是Npplugin文件,其作用是实现多浏览器支持。目前Lodop支持IE系列、IE内核系列(遨游、360、世界之窗、腾讯TT、搜狗等)浏览器,以及Firefox(火狐)系列、Chrome(谷歌)系列、Opera系列、Safari系列等Windows下几乎所有的浏览器。

程序文件有几个预定参数:

-waitXX 该参数设置安装程序运行完毕后自动关闭窗口,这里的XX表示关闭前等待的秒数,如果是0秒则安装(或卸载)成功后立即关闭,例如: wait8

-nowindow 该参数设置安装程序运行时不出现窗口。

-un       该参数使程序执行卸载操作,参数优先于文件名。

-in       该参数使程序执行安装操作,参数优先于文件名。

LodopFuncs.js

该文件是用来引导安装控件的一个JS文件,是个样例,但建议直接采用。其中getLodop的任务是判断浏览器的类型并决定采用哪个对象实例,并检测控件是否安装、是否最新版本、并引导安装或升级。文件内容如下:

function getLodop(oOBJECT,oEMBED){

        var strHtml1="<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='install_lodop.exe'>执行安装</a>,安装后请刷新页面或重新进入。</font>";

        var strHtml2="<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='install_lodop.exe'>执行升级</a>,升级后请重新进入。</font>";

        var strHtml3="<br><br><font color='#FF00FF'>(注:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】中先卸载它)</font>";

        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=strHtml3+document.documentElement.innerHTML;

   if (navigator.appVersion.indexOf("MSIE")>=0) document.write(strHtml1); else

   document.documentElement.innerHTML=strHtml1+document.documentElement.innerHTML;

     } else if (LODOP.VERSION<"6.0.0.1") {

   if (navigator.appVersion.indexOf("MSIE")>=0) document.write(strHtml2); else

   document.documentElement.innerHTML=strHtml2+document.documentElement.innerHTML; 

     }

     //*****如下空白位置适合调用统一功能:*********

 

     //*******************************************

     return LODOP; 

}catch(err){

     document.documentElement.innerHTML="Error:"+strHtml1+document.documentElement.innerHTML;

     return LODOP; 

}

}

其中的关键点是VERSION函数,Lodop提供了这个“读版本号”功能,这样控件的安装和升级任务就交给JS来实现,以下是控件在页面内的调用代码,其中包含getLodop的使用:

<head>

<title></title>

<script language="javascript" src="LodopFuncs.js"></script>

<object  id="LODOP" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 

<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>

</object>

</head>

<body>

<script language="javascript"> 

var LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));

</script>

</body>

以上两段代码相互配合实现了Lodop的安装、调用和升级。之所以将LodopFuncs.js作为一个资源文件来部署,既可以利用浏览器的缓存减少页面内容的重复下载,同时还实现了控件发布统一管理,整个应用系统中只要这一个地方发布Lodop。其它页面直接拷贝嵌入第2段代码就可以了。

三、控件参数

Lodop有如下控件参数,以页面object对象元素的参数形式使用:

Caption

名称:设置控件的显示标题

格式:<param name="Caption" value="我是打印控件lodop">

功能: 控件在页面内一般是以object元素形式被引用。可以通过设置元素的width和height等于0来隐藏控件,不隐藏时可以为控件设置一个标题,以便于看到控件是否被正确安装,以及控件对象在页面内的位置。希望打印预览界面或设计界面内嵌到网页内时,本参数很有用。

Color

名称:设置控件的显示区域颜色

格式:<param name="Color" value="#C0C0C0">

功能:通过该参数设置控件显示区域的底色,对于希望打印预览界面或设计界面内嵌到网页内时,本参数可以让控件容易融于整体页面。

参数值采用超文本颜色形式,可以是三色16进制值组合,也可以是英文颜色名。

 

Border

名称:设置控件的显示区域边界

格式:<param name="Border" value="1">

功能:通过该参数设置控件显示区域的边界,值等于1表示有边界,否则无边界。本参数可以让控件更融于整体页面。


四、打印实例

一般打印

function print(data,orderData){
LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));//得到适配
LODOP.PRINT_INITA(data["upDown"],data["leftRight"],data["width"]-data["leftRight"],data["height"]-data["upDown"],"打印");//打印初始化
LODOP.SET_PRINT_PAGESIZE(1,data["width"]+"mm",data["height"]+"mm","");//设置纸张
var print_item = data.piMap;
$.each(_printItem, function(i, item) {
if(print_item[item]!=null&&print_item[item]!=undefined){
var a = print_item[item]; 
LODOP.ADD_PRINT_TEXT(a.top,a.left,a.width,a.height,orderData[item]);//设置距离打印文本
}
});
LODOP.PRINTA(); //打印
}

在页面内嵌入打印控件

 

<script language="javascript" src="LodopFuncs.js"></script>

<object id="LODOP" 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_lodop.exe"></embed>

</object>

缩放打印图片

function myPreview2() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_IMAGE(30,150,600,400,"<img border='0' src='http://www.baidu.com/img/baidu_logo.gif'/>");

LODOP.SET_PRINT_STYLEA(1,"Stretch",1);//(可变形)扩展缩放模式

LODOP.PREVIEW();

};

function myPreview3() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_IMAGE(30,150,600,80,"<img border='0' src='http://www.baidu.com/img/baidu_logo.gif'/>");

LODOP.SET_PRINT_STYLEA(1,"Stretch",2);//按原图比例(不变形)缩放模式

LODOP.PREVIEW();

};

 

控制表格的打印样式

function myPreview3(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));

var strBodyStyle="<style>table { border: 1 solid #000000;border-collapse:collapse }</style>";

varstrFormHtml=strBodyStyle+"<body>"+document.getElementById("form1").innerHTML+"</body>"

LODOP.ADD_PRINT_TEXT(50,50,260,39,"细线样式打印:");

LODOP.ADD_PRINT_HTM(88,50,300,200,strFormHtml);

LODOP.PREVIEW();

};

打印内容旋转

function CreateOneFormPage(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.SET_PRINT_STYLE("FontName","黑体");

LODOP.SET_PRINT_STYLE("FontSize",15);

LODOP.ADD_PRINT_TEXT(71,162,120,35,"正常内容");

LODOP.ADD_PRINT_TEXT(232,355,325,34,"纯文本逆时针旋转90\n");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_TEXT(181,161,346,34,"纯文本逆时针旋转45\n");

LODOP.SET_PRINT_STYLEA(0,"Angle",45);

LODOP.ADD_PRINT_HTM(230,98,163,200,"<table border=\"1\"><tr>\n<td style=\"writing-mode: tb-rl;\">旋转90</td>\n<td>正常<p>超文本</p><p>内容</p></td>\n</tr></table>\n\n");

};

 

用代码设计复杂的文本打印

function CreateFullBill() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.SET_PRINT_STYLE("FontColor","#0000FF");

LODOP.ADD_PRINT_SHAPE(2,116,43,655,373,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(1,144,44,653,1,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(1,172,44,653,1,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,116,143,1,56,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,116,488,1,56,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,116,574,1,372,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,172,166,1,282,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,172,415,1,282,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(1,454,44,653,1,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,454,130,1,34,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,454,483,1,34,0,1,"#800000");

LODOP.ADD_PRINT_SHAPE(0,64,62,120,1,0,1,"#0000FF");

LODOP.ADD_PRINT_SHAPE(3,29,62,32,32,0,4,"#0000FF");

LODOP.ADD_PRINT_SHAPE(3,21,300,147,75,0,3,"#FF0000");

LODOP.ADD_PRINT_SHAPE(3,26,307,132,65,0,1,"#FF0000");

LODOP.ADD_PRINT_TEXT(33,192,408,30,"中国移动通信集团北京有限公司专用发票");

LODOP.SET_PRINT_STYLEA(0,"FontSize",15);

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(68,326,100,25,"  ");

LODOP.SET_PRINT_STYLEA(0,"FontSize",11);

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(29,98,84,35,"中国移动通信CHINA MOBILE");

LODOP.ADD_PRINT_SHAPE(2,37,69,18,15,0,1,"#0000FF");

LODOP.ADD_PRINT_SHAPE(2,40,73,10,9,0,1,"#0000FF");

LODOP.ADD_PRINT_TEXT(70,64,117,20,"     ");

LODOP.SET_PRINT_STYLEA(0,"FontSize",8);

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(124,58,68,20,"客户名称");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(152,58,68,20,"手机号码");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(124,497,68,20,"受理类别");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(152,497,68,20,"  ");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(465,54,68,20,"大写金额");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(465,495,104,20,"小写金额    : ");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(98,56,47,20,"编号:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(98,259,48,20,"日期:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(97,500,71,20,"发票号码:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(496,54,83,20,"话费帐期:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(496,321,83,20,"营业员工号:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(496,480,93,20,"收款单位名称:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(226,703,27,121,"第二联发票联");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(203,21,17,195,"京地税准印八九号五百万份");

LODOP.SET_PRINT_STYLEA(0,"FontSize",8);

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXT(126,150,100,20,"郭德强");

LODOP.ADD_PRINT_TEXT(151,150,100,20,"13954885188");

LODOP.ADD_PRINT_TEXT(125,584,99,20,"发票打印(1)");

LODOP.ADD_PRINT_TEXT(465,140,198,20,"陆百柒拾捌元叁角零分");

LODOP.ADD_PRINT_TEXT(465,599,70,20,"678.30");

LODOP.ADD_PRINT_TEXT(496,408,59,20,"H112063");

LODOP.ADD_PRINT_TEXT(191,58,100,20,"国内漫游通话");

LODOP.ADD_PRINT_TEXT(191,217,100,20,"584.00");

LODOP.ADD_PRINT_TEXT(222,58,100,20,"增值业务费");

LODOP.ADD_PRINT_TEXT(222,217,100,20,"48.30");

LODOP.ADD_PRINT_TEXT(251,58,100,20,"代收费");

LODOP.ADD_PRINT_TEXT(251,217,100,20,"50.00");

LODOP.ADD_PRINT_TEXT(280,58,100,20,"优惠费");

LODOP.ADD_PRINT_TEXT(280,217,100,20,"4.00");

LODOP.ADD_PRINT_TEXT(98,101,150,20,"101081005747319387");

LODOP.ADD_PRINT_TEXT(97,307,150,20,"20081019 10:28:38");

LODOP.ADD_PRINT_TEXT(152,584,103,20,"138860016786");

LODOP.ADD_PRINT_TEXT(95,571,112,20,"06775516");

LODOP.SET_PRINT_STYLEA(0,"FontName","System");

LODOP.ADD_PRINT_TEXT(76,500,71,20,"发票代码:");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#800000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXT(74,571,112,20,"237090742401");

LODOP.SET_PRINT_STYLEA(0,"FontName","System");

LODOP.SET_PRINT_STYLEA(0,"FontColor","#FF0000");

LODOP.ADD_PRINT_TEXT(496,135,183,20,"200809(20080901-20080930)");

LODOP.ADD_PRINT_TEXT(496,572,112,20,"-王府井中心店营");

LODOP.ADD_PRINT_TEXT(311,217,100,20,"678.30");

LODOP.ADD_PRINT_TEXT(311,58,100,20,"费用合计");

 

}; 

 

 

 

 

 

 

 

 

 

 

 

满页打印和打印页头页尾

function PreviewMytable(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_TABLE(100,5,500,280,document.getElementById("div1").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"TableHeightScope",iRadioValue);

LODOP.PREVIEW();

};

function PrintInFullPage(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));

LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_自定义纸张");

LODOP.SET_PRINT_PAGESIZE(2,0,0,"A4");

LODOP.ADD_PRINT_TABLE("2%","1%","96%","98%",document.getElementById("div1").innerHTML);

LODOP.SET_PREVIEW_WINDOW(0,0,0,800,600,"");

LODOP.PREVIEW();

};

演示使用百分比(%)和满页打印:

 

var LODOP; //声明为全局变量

function myCreatePage() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_ELLIPSE("0%","0%","100%","50%",0,1);

LODOP.ADD_PRINT_TABLE("50%","0%","100%","50%","<body leftmargin=0>"+document.getElementById("table02").innerHTML+"</body>");

};

function myPreview() {

myCreatePage();

LODOP.PREVIEW();

};

 

 

 

 

 

 

 

 

 

 

 

 

 

幅面高度不固定的票据打印

function ReSumMoney() {

var fSumvalue=0;

for (i = 1; i < 8; i++) {

if (document.getElementById("CK"+i).checked) {

fSumvalue=fSumvalue+parseFloat(document.getElementById("DJ"+i).value);

}

}

document.getElementById("HJ").value=fSumvalue.toFixed(2);

};

function MyPreview() {

AddTitle();

var iCurLine=80;//标题行之后的数据从位置80px开始打印

for (i = 1; i < 8; i++) {

if (document.getElementById("CK"+i).checked) {

LODOP.ADD_PRINT_TEXT(iCurLine,15,100,20,document.getElementById("BH"+i).value);

LODOP.ADD_PRINT_TEXT(iCurLine,149,100,20,document.getElementById("MC"+i).value);

LODOP.ADD_PRINT_TEXT(iCurLine,289,100,20,document.getElementById("SL"+i).value);

LODOP.ADD_PRINT_TEXT(iCurLine,409,100,20,document.getElementById("DJ"+i).value);

iCurLine=iCurLine+25;//每行占25px

}

}

LODOP.ADD_PRINT_LINE(iCurLine,14,iCurLine,510,0,1);

LODOP.ADD_PRINT_TEXT(iCurLine+5,20,300,20,"打印时间:"+(new Date()).toLocaleDateString()+" "+(new Date()).toLocaleTimeString());

LODOP.ADD_PRINT_TEXT(iCurLine+5,346,150,20,"合计金额:"+document.getElementById("HJ").value);

LODOP.SET_PRINT_PAGESIZE(3,1385,45,"");//这里3表示纵向打印且纸高按内容的高度1385表示纸宽138.5mm45表示页底空白4.5mm

LODOP.PREVIEW();

};

function AddTitle(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_TEXT(15,102,355,30,"北京市东城区沃乐福商城收款票据");

LODOP.SET_PRINT_STYLEA(1,"FontSize",13);

LODOP.SET_PRINT_STYLEA(1,"Bold",1);

LODOP.ADD_PRINT_TEXT(50,15,100,20,"商品编号");

LODOP.SET_PRINT_STYLEA(2,"FontSize",10);

LODOP.SET_PRINT_STYLEA(2,"Bold",1);

LODOP.ADD_PRINT_TEXT(50,149,100,20,"商品名称");

LODOP.SET_PRINT_STYLEA(3,"FontSize",10);

LODOP.SET_PRINT_STYLEA(3,"Bold",1);

LODOP.ADD_PRINT_TEXT(50,289,100,20,"商品数量");

LODOP.SET_PRINT_STYLEA(4,"FontSize",10);

LODOP.SET_PRINT_STYLEA(4,"Bold",1);

LODOP.ADD_PRINT_TEXT(50,409,100,20,"单价()");

LODOP.SET_PRINT_STYLEA(5,"FontSize",10);

LODOP.SET_PRINT_STYLEA(5,"Bold",1);

LODOP.ADD_PRINT_LINE(72,14,73,510,0,1);

};

 

 

在页面嵌入背景图片

function myShow4() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_TEXT(43,250,75,20,"东北地区");

LODOP.ADD_PRINT_TEXT(96,173,75,20,"华北地区");

LODOP.ADD_PRINT_TEXT(187,208,60,20,"华南地区");

LODOP.ADD_PRINT_TEXT(137,256,60,20,"华东地区");

LODOP.ADD_PRINT_TEXT(136,176,61,20,"华中地区");

LODOP.ADD_PRINT_TEXT(77,76,60,20,"西北地区");

LODOP.ADD_PRINT_TEXT(172,129,60,20,"西南地区");

LODOP.ADD_PRINT_LINE(97,224,57,284,0,1);

LODOP.ADD_PRINT_LINE(89,118,107,177,0,1);

LODOP.ADD_PRINT_LINE(169,152,152,213,0,1);

LODOP.ADD_PRINT_LINE(117,195,134,201,0,1);

LODOP.ADD_PRINT_LINE(163,231,190,239,0,1);

LODOP.ADD_PRINT_LINE(147,234,148,253,0,1);

LODOP.ADD_PRINT_TEXT(94,395,24,97,"地区方位图");

 

LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0' src='http://static13.photo.sina.com.cn/middle/4fe4ba17x873a8d10515c&690'>");

LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW",1); //注:"BKIMG_IN_PREVIEW"-预览包含背景图 "BKIMG_IN_FIRSTPAGE"- 仅首页包含背景图

LODOP.PREVIEW();

};

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

强制分页

function MyPreview() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.SET_PRINT_PAGESIZE(1,500,508,"");

for (i = 1; i < 8; i++) {

LODOP.NewPage();

LODOP.ADD_PRINT_RECT(10,18,128,160,0,1);

LODOP.ADD_PRINT_TEXT(31,33,111,20,"商品编号:"+document.getElementById("BH"+i).value);

LODOP.ADD_PRINT_TEXT(69,33,111,20,"商品名称:"+document.getElementById("MC"+i).value);

LODOP.ADD_PRINT_TEXT(107,33,111,20,"商品数量:"+document.getElementById("SL"+i).value);

LODOP.ADD_PRINT_TEXT(146,33,111,20,"商品单价:"+document.getElementById("DJ"+i).value);

LODOP.PREVIEW();

}

};

 

分页打印综合表格

function PreviewMytable(){

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_TABLE(128,"5%","90%",314,document.getElementById("div2").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"Vorient",3);

LODOP.ADD_PRINT_HTM(20,"5%","90%",109,document.getElementById("div1").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

LODOP.ADD_PRINT_HTM(444,"5%","90%",54,document.getElementById("div3").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

LODOP.NewPageA();

LODOP.ADD_PRINT_TABLE(112,"5%","90%",328,document.getElementById("div2").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"Vorient",3);

LODOP.ADD_PRINT_HTM(26,"5%","90%",80,document.getElementById("div4").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",4);

LODOP.ADD_PRINT_TEXT(454,96,"76.25%",20,"( “页脚,紧跟表格)");

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",4);

LODOP.SET_PRINT_STYLEA(0,"FontSize",12);

LODOP.SET_PRINT_STYLEA(0,"FontColor","#FF0000");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

LODOP.SET_PRINT_STYLEA(0,"Horient",3);

LODOP.ADD_PRINT_TEXT(3,653,135,20,"总页号:第#/&");

LODOP.SET_PRINT_STYLEA(0,"ItemType",2);

LODOP.SET_PRINT_STYLEA(0,"Horient",1);

LODOP.ADD_PRINT_TEXT(3,34,196,20,"总页眉:《两个发货单的演示》");

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

LODOP.PREVIEW();

};

 

 

 

演示如何分页输出页面内容:

var LODOP; //声明为全局变量

function prn1_preview() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_HTM(88,200,350,600,document.getElementById("div1").innerHTML);

LODOP.NewPage();

LODOP.ADD_PRINT_HTM(88,200,350,600,document.getElementById("div2").innerHTML);

LODOP.NewPage();

LODOP.ADD_PRINT_HTM(88,200,350,600,document.getElementById("div3").innerHTML);

LODOP.PREVIEW();

};

function prn2_preview() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

strHTML="<table border='0' width='100%' >";

strHTML=strHTML+"<tr><td>";

strHTML=strHTML+document.getElementById("div1").innerHTML;

strHTML=strHTML+"</td></tr>";

strHTML=strHTML+"<tr><td>";

strHTML=strHTML+document.getElementById("div2").innerHTML;

strHTML=strHTML+"</td></tr>";

strHTML=strHTML+"<tr><td>";

strHTML=strHTML+document.getElementById("div3").innerHTML;

strHTML=strHTML+"</td></tr>";

LODOP.ADD_PRINT_TABLE(88,200,350,1,strHTML);

LODOP.PREVIEW();

};

function prn3_preview() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM')); 

LODOP.ADD_PRINT_HTM(88,150,450,"100%",document.getElementById("div1_2_3").innerHTML);

LODOP.PREVIEW();

};

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

演示内容关联后按顺序打印: 

LODOP.ADD_PRINT_TABLE(100,5,500,280,document.getElementById("tablediv").innerHTML);

LODOP.ADD_PRINT_TABLE(26,0,500,280,document.getElementById("tablediv").innerHTML);

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

LODOP.ADD_PRINT_TEXT(15,50,200,25,"制表日期:"+LODOP.FORMAT("TIME:YYYY年MM月DD日","DATE"));

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",2);

LODOP.ADD_PRINT_TEXT(15,300,200,25,"双表输出:Admin");

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",2); 

LODOP.ADD_PRINT_TABLE(100,5,500,280,document.getElementById("tablediv").innerHTML);

LODOP.ADD_PRINT_TEXT(15,50,200,25,"制表日期:"+LODOP.FORMAT("TIME:YYYY年MM月DD日","DATE"));

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

LODOP.ADD_PRINT_TEXT(15,300,200,25,"单表制表:guest");

LODOP.SET_PRINT_STYLEA(0,"LinkedItem",1);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

超多页打印演示:

function MyPREVIEW() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));

LODOP.PRINT_INIT("中文学位证书打印");

LODOP.SET_PRINT_PAGESIZE(1,2970,2100,"");

LODOP.SET_PRINT_STYLE("FontSize",16);

LODOP.SET_PRINT_STYLE("Bold",1);

for (j = 1; j <=10; j++) {

CreateOnePage("姓名"+j,"",j);

};

LODOP.SET_PREVIEW_WINDOW(0,0,0,0,0,"");

LODOP.PREVIEW();

};

function CreateOnePage(XM,XB,BH){

LODOP.NewPage();

LODOP.ADD_PRINT_TEXTA("text01",67,132,137,35,XM);

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXTA("text02",67,280,40,35,XB);

LODOP.ADD_PRINT_TEXTA("text03",67,329,70,35,"1979");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXTA("text04",67,421,50,35,"09");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text05",67,489,40,35,"09");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text06",223,220,76,35,"理学");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text07",121,130,332,35,"应用物理与微电子技术");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text08",271,482,34,35,"");

LODOP.ADD_PRINT_TEXTA("text09",271,616,32,35,"");

LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

LODOP.ADD_PRINT_TEXTA("text10",300,131,289,35,"合肥工业大学");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text11",364,210,261,35,"103700002009000"+BH);

LODOP.ADD_PRINT_TEXTA("text12",365,753,66,35,"2009");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

LODOP.ADD_PRINT_TEXTA("text13",365,843,37,35,"12");

LODOP.ADD_PRINT_TEXTA("text14",365,911,54,35,"31");

LODOP.SET_PRINT_STYLEA(0,"Alignment",2);

};

 

 

 

 

 

 

 

 

 

 

 

 

 

演示打印Table的分页小计和合计:

利用专为函数ADD_PRINT_TABLE使用的特殊超文本元素属性可以轻松实现分页小计、累计、分类统计、页数及总合计等功能,
该属性有tdata、format、tclass、tindex四个,可以用在table内任何元素上,如果元素在tfoot内则每页都输出。
这些属性的解释和演示如下:

一、设置统计类型的元素属性名是“tdata”,其值和含义为:
subCount---本页行数,即本列的单元格行数;
subSum---本页合计,即本列的数值合计;
subAverage---本页平均数,即本页合计除以本页行数;
Count---累计行数,即从第一页到本页的行数累加值;
Sum---累计数,即从第一页到本页的本列数值的累加值;
Average---累计平均数,即累计数除以累计行数;
allCount---总行数,即全表(Table)的本列行数;
allSum---总计数,即全表(Table)的本列数值的总和;
allAverage---总平均数,即全表总计数除以总行数;
二、设置数据格式的元素属性名是“format”,format值如下样式:
0” “0.00” “#.##” “#,##0.00”“0.000E+00”“#.###E-0 ”“UpperMoney(大写金额)”等等...
三、分类统计的“类名”用元素属性“tclass”,tclass值任意设置,参见本演示的“A型”“B型”个数统计。
四、一般要求统计结果的位置与数据的列位置一致或内含在数据列内,如果位置无法一致,
可以用“tindex”指定对应的数据列,该值是数字型的列序号,从1起始,参见本演示的“B型”统计。
五、统计结果的占位符是任意个“#”组成的字符串,当结果值较大时,注意占位符要足够多,除非周围有空白区

<tr>

<td width="481" colspan="2">本表截止当前行累积金额:

</td>

<td width="657" colspan="3"><font color="#0000FF" tdata="Sum" format="#,##0.00" tindex="3" >######</font>

</td>

</tr>

 

<tr>

<td width="374" colspan="2">截止表尾累积金额

</td>

<td width="202"><font color="#0000FF" tdata="Sum" format="#,##0.00" tindex="3" >######</font>

</td>

<td width="363" colspan="2"><font color="#0000FF" tdata="Sum" format="UpperMoney" tindex="3" >######</font>

</td>

</tr>

<tfoot>

<tr>

<th width="20%" tdata="subCount" format="#" align="left">本页行数:<font color="#0000FF">######</font></th>

<th width="26%" tdata="subSum" format="#.##">本页数量小计:<font color="#0000FF">######</font></th>

<th width="14%" align="right">本页金额小计</th>

<th width="19%" tdata="subSum" format="#,##0.00" align="right"><font color="#0000FF">###元</font></th>

<th width="21%" tdata="subAverage" format="#.00" align="left">本页均价:<font color="#0000FF">######</font></th>

</tr>

<tr>

<th width="20%" tdata="Count" format="#" align="left">累计行数:<font color="#0000FF">######</font></th>

<th width="26%" tdata="Sum" format="#.##">数量累计:<font color="#0000FF">######</font></th>

<th width="14%" align="right">金额累计</th>

<th width="19%" tdata="Sum" format="#,##0.00" align="right"><font color="#0000FF">¥###</font></th>

<th width="21%" tdata="Average" format="#.00" align="left">累计均价:<font color="#0000FF">######</font></th>

</tr>

<tr>

<th width="20%" tdata="allCount" format="#" align="left">全表行数:<font color="#0000FF">######</font></th>

<th width="26%" tdata="allSum" format="#.##">全表数量总计:<font color="#0000FF">######</font></th>

<th width="14%" align="right">全表金额总计</th>

<th width="19%" tdata="allSum" format="#,##0.00" align="right"><font color="#0000FF">¥###</font></th>

<th width="21%" tdata="allAverage" format="#.00" align="left">全表均价:<font color="#0000FF">######</font></th>

</tr>

<tr>

<th width="22%" tdata="subCount" format="0" align="left" colspan="2">

本页A型:<font color="#0000FF" tclass="a">##</font>行,B型:

<font color="#0000FF" tclass="b" tindex="1">##</font>

</th>

<th width="12%" tdata="pageNO" format="#" align="left" colspan="2">

<p align="center"><font color="#0000FF">#</font></p>

</th>

<th width="10%" tdata="pageCount" format="#" align="left">

<p align="center"><font color="#0000FF">#</font>

</th>

</tr>

</tfoot>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

如何打印条形码:

function CreatePrintPage() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));  

LODOP.PRINT_INITA(0,0,800,1600,"打印控件功能演示_Lodop功能_打印条码");

LODOP.ADD_PRINT_BARCODE(28,34,307,47,"128A","123456789012");

LODOP.ADD_PRINT_BARCODE(84,34,342,78,"128B","123456789012");

LODOP.SET_PRINT_STYLEA(0,"FontSize",20);

LODOP.ADD_PRINT_BARCODE(176,34,199,58,"128C","888888");

LODOP.SET_PRINT_STYLEA(0,"Color",255);

LODOP.ADD_PRINT_BARCODE(237,34,153,54,"EAN8","69012341");

LODOP.ADD_PRINT_BARCODE(296,34,360,47,"EAN13","6901234567892");

LODOP.ADD_PRINT_BARCODE(351,34,360,36,"EAN128A","123456789012");

LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);

LODOP.ADD_PRINT_BARCODE(403,34,360,47,"EAN128B","123456789012");

LODOP.ADD_PRINT_BARCODE(462,34,360,47,"EAN128C","123456789012");

LODOP.ADD_PRINT_BARCODE(513,34,360,47,"Code39","*123ABC4567890*");

LODOP.SET_PRINT_STYLEA(0,"Color",16711680);

LODOP.ADD_PRINT_BARCODE(570,34,360,47,"39Extended","*1234567890*");

LODOP.ADD_PRINT_BARCODE(621,34,360,47,"2_5interleaved","123456789012");

LODOP.ADD_PRINT_BARCODE(677,34,360,47,"2_5industrial","123456789012");

LODOP.ADD_PRINT_BARCODE(729,34,360,47,"2_5matrix","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Color",8421440);

LODOP.ADD_PRINT_BARCODE(787,34,360,47,"UPC_A","089600124569");

LODOP.ADD_PRINT_BARCODE(844,34,135,64,"UPC_E0","08960007");

LODOP.ADD_PRINT_BARCODE(238,426,104,62,"UPC_E1","1111111");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(209,560,62,57,"UPCsupp2","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(374,434,119,59,"UPCsupp5","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(370,559,44,63,"Code93","BJ100080");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(241,663,73,59,"93Extended","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Angle",-90);

LODOP.ADD_PRINT_BARCODE(693,424,49,79,"MSI","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Color",16711935);

LODOP.SET_PRINT_STYLEA(0,"ShowBarText",0);

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(749,559,44,68,"PostNet","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Angle",90);

LODOP.ADD_PRINT_BARCODE(572,659,44,73,"Codabar","123456789012");

LODOP.SET_PRINT_STYLEA(0,"Angle",-90);

LODOP.ADD_PRINT_BARCODE(30,423,116,114,"QRCode","123123123版本3的最大值是42个字符");

LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",3);

LODOP.ADD_PRINT_BARCODE(31,587,168,146,"QRCode","1234567890版本7的最大值是122个字符123123");

LODOP.SET_PRINT_STYLEA(0,"GroundColor",16744448);

LODOP.SET_PRINT_STYLEA(0,"QRCodeVersion",7);

};

 

 

 

 

 

单据打印

printDj:function(){

DjglProcess.lodop=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));

var strBodyStyle="<style>" +

" .title_print { border-style: solid;    border-width: 0 0 1 0; font-size: 24px; font-family: 仿宋黑体;  font-weight: BOLD;}" +

".text_print{  border-style: solid;        border-width: 0 0 0 0;        font-family: 楷体_GB2312;        font-size: 14px;        }" +

".head_print{           border-style: solid;        border-width: 0 0 0 0;        font-family: 宋体;        font-size: 14px;        }" +

".text2_print {        font-size: 14px;        font-family: 宋体;    }" +

".num_print {border-style: solid;   border-width: 0 0 0 0; text-align: right; ime-mode: disabled;        width: 100%;         font-size: 14px;   }" +

" .trHeight_print{  height:32px;     } </style>";

strFormHtml=strBodyStyle+"<body>"+document.getElementById("_print").innerHTML+"</body>";

DjglProcess.lodop.add_print_htm(10,60,840,700,strFormHtml);

//DjglProcess.lodop.PRINTA();  //选择打印机打印

DjglProcess.lodop.PREVIEW();  //预览打印

//DjglProcess.lodop.PRINT();  //直接打印

},

 

 

 

 

 

 

 

入库单列表打印

<script type="text/javascript">

function prn_Preview() {

CreatePrintPage();

   LODOP.PREVIEW(); //打印预览

  //LODOP.PRINT_SETUP();  //打印维护

  //LODOP.PRINT_DESIGN();  //打印设计

};

function CreatePrintPage() {

LODOP=getLodop(document.getElementById('LODOP'),document.getElementById('LODOP_EM'));  

LODOP.PRINT_INITA(0,0,800,1600,"打印控件功能演示_Ext");

AddText();

LODOP.ADD_PRINT_TEXT(3,653,135,20,"总页号:第#/&");

LODOP.SET_PRINT_STYLEA(0,"FontSize",11);

LODOP.SET_PRINT_STYLEA(0,"ItemType",2);

LODOP.SET_PRINT_STYLEA(0,"Horient",1);

LODOP.ADD_PRINT_TEXT(3,34,196,20,"总页眉:《入库单的演示》");

LODOP.SET_PRINT_STYLEA(0,"FontSize",11);

LODOP.SET_PRINT_STYLEA(0,"ItemType",1);

}

function AddText(){

LODOP.ADD_PRINT_TEXT(25,382,355,30,dj_grid.title);

LODOP.SET_PRINT_STYLEA(1,"FontSize",16);

LODOP.SET_PRINT_STYLEA(1,"Bold",1);

//设置表格样式

var strTableStyle="<style type='text/css'>table{width:'100%';border-collapse: collapse;} table thead td b{font-size: 25px;} table tr td{font-size: 13px;} table tfoot td{font-size: 15px;}</style>";

//将数据拼成一个table

var strTableStartHtml="<table border='1' width='100%' bordercolor='#336699' cellpadding='0' cellspacing='0' align='center'>";

var strTableEndHtml="</table>";

var strTableTheadHtml="<thead style='height: 30px' bgcolor='#efefef'>";

var strTableTrHtml="";

for(var i=0;i<dj_grid.getColumnModel().getColumnCount(true);i++){

var td="<td nowrap align='center' style=font-size: 15px><b>"+dj_grid.getColumnModel().getColumnHeader(i)+"</b></td>";

strTableTheadHtml+=td;

}

strTableTheadHtml+="<td nowrap align='center'><b>条形码</b></td>";

strTableTheadHtml+="</thead>";

var zjeTotal=0;

for(var i=0;i<dj_grid.getStore().getCount();i++){

var td ="<tr style='height: 30px'><td align='center'>";

td+=dj_grid.getStore().getAt(i).get("djh");

td+="</td><td align='center'>";

td+=Ext.util.Format.date(dj_grid.getStore().getAt(i).get("djrq"),'Ymd');

td+="</td><td align='center'>";

td+=dj_grid.getStore().getAt(i).get("ghsmc");

td+="</td><td align='right'>";

var zje=dj_grid.getStore().getAt(i).get("zje");

zjeTotal+=parseFloat(zje);

td+=Ext.util.Format.number(zje,'0,0.00');

td+="  </td><td align='center'>";

td+=dj_grid.getStore().getAt(i).get("djzt");

td+="</td><td align='center'>";

td+="</td></tr>";

strTableTrHtml+=td;

}

var strTableTfoot="<tr style='height: 30px'><td align='center'><b>合计</b></td><td> </td><td> </td><td align='right'><b>"+Ext.util.Format.number(zjeTotal,'0,0.00')+"</b>     </td><td> </td><td> </td></tr>";

var strPageFooter="<tfoot style='height: 30px'><td align='center'><b><表格页脚>本页动态合计</b></td><td tdata='pageNO' format='#' align='center'><p align='center'><b><font color='#0000FF'>#</font></b></p></td><td tdata='pageCount' format='#' align='center'><p align='center'><b><font color='#0000FF'>#</font></b></td><td tdata='subSum' format='#,##0.00' align='left'><font color='#0000FF'>#</font></b>     </td><td> </td><td> </td></tfoot>";

LODOP.ADD_PRINT_HTM(50,0,800,1000,strTableStyle);

LODOP.ADD_PRINT_TABLE(75,0,"100%","85%",strTableStartHtml+strTableTheadHtml+strTableTrHtml+strPageFooter+strTableEndHtml);

var j=81;

for(var i=0;i<dj_grid.getStore().getCount();i++){

j=j+30;

LODOP.ADD_PRINT_BARCODE(j,734,37,22,"128A",dj_grid.getStore().getAt(i).get("djh"));

if(j%1011==0){j=81;LODOP.NewPage();}

}

};