web打印实现方案 Lodop6.034 使用方法总结

官文下载:

http://mtsoftware.v053.gokao.net/download.html

本地 Lodop6.034 版本下载:/Files/tiger8000/Lodop6.034.rar

假设你的 lodop 打印控件放在你项目的根目录下的 Lodop 目录内

 printTable.aspx 文件存在于你项目中的 PrintCenter 目录内。在此文件的 html 页面中加入:

 

  < script type = " text/javascript "  language = " javascript "  src = " ../Lodop/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 = " ../Lodop/install_lodop.exe " ></ embed >
</ object >  

 

其中:

 

< embed id = " LODOP_EM "  type = " application/x-print-lodop "  width = " 0 "  height = " 0 "  pluginspage = " ../Lodop/install_lodop.exe " ></ embed >

 

是专为 FireFox 浏览器设计的代码,如果你这个打印控件只在 IE 上应用,那么上面这名话完全可以不用的。

只这样加就行了:

 

     < script type = " text/javascript "  language = " javascript "  src = " ../Lodop/LodopFuncs.js " ></ script >
< object  id = " LODOP "  classid = " clsid:2105C259-1E0C-4534-8141-A753534CB4CA "  width = " 0 "  height = " 0 " >  
</ object >  

 

 

这样就把 lodop 打印控件在本页调用过来了。

 

实现打印一个俱有 100 行的数据报表,要分页打印,要求,用A4纸纵向打印,在下面的页角,显示当前页码及总页数。

正常情况下,你设定了打印纸张规格后,如 A4 或是自定义纸张大小,然后,你定义了 打印输出的大小

LODOP.ADD_PRINT_TABLE(11033750900, document.getElementById("printdiv").innerHTML);

距上边 110 象素,左边 33 像素,宽 750象素,高 900 象素这外区域内打印内容。打印控件会自动根据纸张大小和你打印区长,高,计算出打印页数,会自动分页,你需要做的就是不断调整打印区 边距,宽,高 :11033750900

然后,自己打印出  当前页/总页数 .

在 aspx 页中加入:

 

< script language = " javascript "  type = " text/javascript " >
    var LODOP; 
// 声明为全局变量 
    function prn1_preview() {
        PrintMytable();
        LODOP.PREVIEW();
    };
    function prn1_print() {
        PrintMytable();
        LODOP.PRINT();
    };

    function PrintMytable() {
        LODOP 
=  getLodop(document.getElementById( ' LODOP ' ), document.getElementById( ' LODOP_EM ' ));
        LODOP.PRINT_INIT(
" 银燕公司宽带收费明细 " );
        LODOP.SET_PRINT_PAGESIZE(
1 0 0 " A4 " );
        LODOP.ADD_PRINT_TEXT(
30 280 500 50 " 银燕公司宽带财务报表明细 " )
        LODOP.SET_PRINT_STYLEA(
1 " ItemType " 1 );
        LODOP.SET_PRINT_STYLEA(
1 " FontSize " 14 );
        LODOP.SET_PRINT_STYLEA(
1 " Bold " 1 );
        LODOP.ADD_PRINT_TEXT(
1050 370 200 22 " 第#页/共&页 " );
        LODOP.SET_PRINT_STYLEA(
2 " ItemType " 2 );
        LODOP.SET_PRINT_STYLEA(
2 " HOrient " 1 );
        LODOP.ADD_PRINT_TEXT(
90 50 100 50 " 共:<%=numb%> 条记录 " )
        LODOP.SET_PRINT_STYLEA(
3 " ItemType " 1 );
        LODOP.ADD_PRINT_TEXT(
90 300 350 50 " 时间范围:<%=begindt%> 至 <%=enddt%> " )
        LODOP.SET_PRINT_STYLEA(
4 " ItemType " 1 );
        
// LODOP.ADD_PRINT_TABLE(110, 33, 750, 900, document.documentElement.innerHTML);
        LODOP.ADD_PRINT_TABLE( 110 33 750 900 , document.getElementById( " printdiv " ).innerHTML);
    };    
   
</ script >  

 

然后,下面是要打印的工资报表 table

 

 

   < div id = " printdiv " >
       
< table width = " 90% "  align = " center "  border = " 1 "  cellpadding = " 0 "  cellspacing = " 0 "  bordercolor = " #000000 "  bordercolorlight = " #000000 "  bordercolordark = " #000000 "  id = " tb01 "  style = " border-collapse:collapse " >
                   
< asp:Repeater ID = " Repeater2 "  runat = " server " >
                     
< HeaderTemplate >
                     
< thead >
                         
< tr bgcolor = " #F8F8FF " >
                            
< th align = " center "  height = " 30 " > 序号 </ th >
                            
< th align = " center " > 姓名 </ th >
                            
< th align = " center " > 账号 </ th >                           
                            
< th align = " center " > 网费 </ th >
                            
< th align = " center " > 网费返款 </ th >
                            
< th align = " center " > 押金 </ th >
                            
< th align = " center " > 押金返款 </ th >
                            
< th align = " center " > 安装费 </ th >
                            
< th align = " center " > 安装费返款 </ th >
                            
< th align = " center " > 卖Modem款 </ th >
                            
< th align = " center " > Modem返款 </ th >
                            
< th align = " center " > 转账 </ th >
                            
< th align = " center " > 缴费日期 </ th >
                        
</ tr >
                     
</ thead >
                     
</ HeaderTemplate >
                     
< ItemTemplate >
                      
< tbody >
                         
< tr height = " 20 "   style = " cursor:hand "  bgColor = " #ffffff "  onmouseover = " javascript:this.style.backgroundColor='#FFCC33'; "     onmouseout = " javascript:this.style.backgroundColor='#ffffff'; " >
                            
< td align = " center " ><% #Container.ItemIndex  +   1 %></ td >
                            
< td align = " center " ><% #Eval( " 姓名 " ) %></ td >
                            
< td align = " center " ><% #Eval( " 账号 " ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 网费 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 网费返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 押金 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 押金返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 安装费 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 安装费返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 卖Modem款 " )),  2 ) %></ td >   
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 卖Modem款返款 " )),  2 ) %></ td >      
                            
< td align = " center " ><% #Eval( " 转账 " ) %></ td >
                            
< td align = " center " ><% #Eval( " 提交日期 " , " {0:yyyy/MM/dd} " ) %></ td >
                        
</ tr >
                        
</ tbody >
                     
</ ItemTemplate >
                     
< AlternatingItemTemplate >
                      
< tbody >
                     
< tr height = " 20 "  style = " cursor:hand "  bgColor = " #f1f1f1 "  onmouseover = " javascript:this.style.backgroundColor='#FFCC33'; "  onmouseout = " javascript:this.style.backgroundColor='#f1f1f1'; " >
                           
< td align = " center " ><% #Container.ItemIndex  +   1 %></ td >
                            
< td align = " center " ><% #Eval( " 姓名 " ) %></ td >
                            
< td align = " center " ><% #Eval( " 账号 " ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 网费 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 网费返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 押金 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 押金返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 安装费 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 安装费返款 " )),  2 ) %></ td >
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 卖Modem款 " )),  2 ) %></ td >   
                            
< td align = " center " ><% #Math.Round(Convert.ToDecimal(Eval( " 卖Modem款返款 " )),  2 ) %></ td >      
                            
< td align = " center " ><% #Eval( " 转账 " ) %></ td >
                            
< td align = " center " ><% #Eval( " 提交日期 " , " {0:yyyy/MM/dd} " ) %></ td >
                        
</ tr >
                       
</ tbody >
                     
</ AlternatingItemTemplate >
                     
< FooterTemplate >
                      
< tr bgcolor = " #FFF8DC "   >
                            
< td align = " center "  height = " 30 " > 合计 </ td >
                            
< td ></ td >
                            
< td ></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= wangfei %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= wangfeifankuan %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= yajin %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= yajinfankuan %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= anzhuangfei %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= anzhuangfeifan %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= maimaokuan %></ td >
                            
< td align = " center "   class = " bigmoneyfont " ><%= maimaokuanfan %></ td >
                            
< td ></ td >
                            
< td ></ td >
                        
</ tr >     
                     
</ FooterTemplate >
                   
</ asp:Repeater >
             
</ table >
         
</ div >     

 1、LODOP.SET_PRINT_PAGESIZE(100"A4");

1 纵向打印

0 打印纸张的宽度 为0 ,可自定义宽

0 打印纸张的高度 为 0 ,可自定义高

A4 指定用 A4 纸打印

当宽度和高度都设为 0 的时候,才能指定用特定的纸型打印,如:A4 ,B5 等。

2、

 LODOP.ADD_PRINT_TEXT(30, 280, 500, 50, "银燕公司宽带财务报表明细")
        LODOP.SET_PRINT_STYLEA(1, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(1, "FontSize", 14);
        LODOP.SET_PRINT_STYLEA(1, "Bold", 1);

第一句:距上 30,距左280,打印区宽 500 ,打印区高 50 这样的一个区域内打印出文字”银燕公司宽带财务报表明细“

第二句:指定刚才打印的这句话 ItemType属性,1为页眉页脚,2为页号码,3为页数,0 为普通项。

第三句:指定刚才打印的这句话 FontSize 属性为 14pt

第四句:指定刚才打印的这句话,加粗显示。Bold 为1 代表加粗,0代表正常显示。

LODOP.SET_PRINT_STYLEA(1, "FontSize", 14);
中最前面的那个参数:1 ,是指的,对页面中加入的 LODOP.ADD_PRINT 元素的索引,指定是哪 一元素。

因为  LODOP.ADD_PRINT_TEXT(30, 280, 500, 50, "银燕公司宽带财务报表明细")
是 最向加的元素,所以它索引为 第 1 项。

 

3

LODOP.ADD_PRINT_TEXT(1050, 370, 200, 22, "第#页/共&页");
        LODOP.SET_PRINT_STYLEA(2, "ItemType", 2);
        LODOP.SET_PRINT_STYLEA(2, "HOrient", 1);

在距上边界 1050 象素,左 370,宽为200,高为22  这样一个区域内打印页码及总页数。

然后,指定这个索 引为2 的这个元素的   ItemType属性,1为页眉页脚,2为页号码,3为页数,0 为普通项。

只有当指定此元素 ItemType属性,2为页号码 的时候,

LODOP.ADD_PRINT_TEXT(1050, 370, 200, 22, "第#页/共&页"); 就会在每个页的固定位置都显示,

才会显示当前页码数及总页数

 

4

 LODOP.ADD_PRINT_TEXT(90, 50, 100, 50, "共:<%=numb%> 条记录")

在指定区域内打印总记录数
        LODOP.SET_PRINT_STYLEA(3, "ItemType", 1);

指定刚才加入的这个索引为第3个元素的 ItemType属性,1为页眉页脚
        LODOP.ADD_PRINT_TEXT(90, 300, 350, 50, "时间范围:<%=begindt%> 至 <%=enddt%>")

在指定区域内打印时间范围
        LODOP.SET_PRINT_STYLEA(4, "ItemType", 1);

指定刚才加入的这个索引为第4个元素的 ItemType属性,1为页眉页脚
        //LODOP.ADD_PRINT_TABLE(110, 33, 750, 900, document.documentElement.innerHTML);

用这个写法可以打印整个页面上的 table表
        LODOP.ADD_PRINT_TABLE(110, 33, 750, 900, document.getElementById("printdiv").innerHTML);

用这种写法也可以打印整个页面中指定为 div 的ID 为 "printdiv" 内的 table

 

二、 打印某一整个 aspx 页。

 

< script type = " text/javascript "  language = " javascript "  src = " ../Lodop/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 = " ../Lodop/install_lodop.exe " ></ embed >
</ object >  
< script language = " javascript "  type = " text/javascript " >
    var LODOP; 
// 声明为全局变量      
    function PrintOneURL(strID) {
        LODOP 
=  getLodop(document.getElementById( ' LODOP ' ), document.getElementById( ' LODOP_EM ' ));
        LODOP.PRINT_INIT(
" 打印控件功能演示_Lodop功能_按网址打印 " );
        LODOP.ADD_PRINT_URL(
30 20 746 " 100% " , document.getElementById(strID).value);
        LODOP.SET_PRINT_STYLEA(
1 " HOrient " 3 );
        LODOP.SET_PRINT_STYLEA(
1 " VOrient " 3 );
        LODOP.PREVIEW();
    };
       
</ script >

 
< input type = " hidden "  id = " T1 "  size = " 54 "  value = " ../PrintSinglePage.aspx " />
     
< a href = " javascript:PrintOneURL('T1'); " > 预览打印 </ a >

 

 

你可能感兴趣的:(web打印)