在项目开发中,经常会用到页面打印的功能,在ASP.NET环境下推荐一款web打印控件smsx.cab。

    使用方法:一般会先定义一个用于打印的母版页(Print.Master),在母版页上做好布局,包括页面布局、js 的引用、smsx.cab控件加载、打印和预览按钮的放置。

下载链接:http://download.csdn.net/detail/nxgliming/6668999

母版页(Print.Master):

  1. <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Print.master.cs" Inherits="PdSecrity.Pages.Print.Print" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title>打印</title>
  7. <asp:ContentPlaceHolder ID="head" runat="server">
  8. </asp:ContentPlaceHolder>
  9. <style media="print">
  10. .Noprint
  11. {
  12. display: none;
  13. }
  14. .w3cbbs
  15. {
  16. page-break-after: always;
  17. }
  18. </style>
  19. </head>
  20. <script src="<%= Page.ResolveClientUrl("~/PdSecrity/Scripts/jquery-1.10.2.min.js")%>"
  21. type="text/javascript"></script>
  22. <script src="<%= Page.ResolveClientUrl("~/PdSecrity/Scripts/Print.js")%>" type="text/javascript"></script>
  23. <body>
  24. <form id="form1" runat="server">
  25. <!--下面的这个objec标签就是加载t加载smsx.cab控件用-->
  26. <object id="factory" style="display: none" codebase="<%= Page.ResolveClientUrl("~/PdSecrity/Scripts/smsx.cab")%>#VVersion=6,6,440,26"
  27. classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext>
  28. </object>
  29. <script>
  30. $(document).ready(function () {
  31. //加载打印设置
  32. SetPrintSettings();
  33. });
  34. </script>
  35. <table align="center">
  36. <tr class="Noprint">
  37. <td>
  38. <input id="Button1" type="button" value="打印" class="btnbg" onclick="Print();" />
  39. <input id="Button2" type="button" value="预览" class="btnbg" onclick="Preview();" />
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
  45. </asp:ContentPlaceHolder>
  46. </td>
  47. </tr>
  48. </table>
  49. </form>
  50. </body>
  51. </html>

Print.js,主页用于打印的一些设置

  1. //预览
  2. function Preview() {
  3. document.all.factory.printing.Preview();
  4. }
  5.  
  6. function Print() {
  7. document.all.factory.printing.Print(false); //无确认打印,true时打印前需进行确认
  8. }
  9.  
  10. function PrintSetup() {
  11. document.all.factory.printing.PageSetup();
  12. }
  13.  
  14. function SetPrintSettings() {
  15. // -------------------基本功能,可免费使用-----------------------
  16. document.all.factory.printing.header = ""; //页眉
  17. document.all.factory.printing.footer = ""; //页脚
  18. ////document.all.factory.printing.SetMarginMeasure(1); //页边距单位,1为毫米,2为英寸//边距设置,需要注意大部分打印机都不能进行零边距打印,即有一个边距的最小值,一般都是6毫米以上
  19. //设置边距的时候时候如果设置为零,就会自动调整为它的最小边距
  20. document.all.factory.printing.leftMargin = ; //左边距
  21. document.all.factory.printing.topMargin = ; //上边距
  22. document.all.factory.printing.rightMargin = ; //右边距
  23. document.all.factory.printing.bottomMargin = ; //下边距
  24. document.all.factory.printing.portrait = true; //是否纵向打印,横向打印为false
  25. //--------------------高级功能---------------------------------------------
  26. //document.all.factory.printing.printer = "EPSON LQ-1600KIII"; //指定使用的打印机
  27. //document.all.factory.printing.printer = "\\\\cosa-data\\HPLaserJ";//如为网络打印机,则需要进行字符转义
  28. ////document.all.factory.printing.paperSize = "A4"; //指定使用的纸张
  29. document.all.factory.printing.paperSource = "Manual feed"; //进纸方式,这里是手动进纸
  30. ////document.all.factory.printing.copies = 1; //打印份数
  31. ////document.all.factory.printing.printBackground = false; //是否打印背景图片
  32. ////document.all.factory.printing.SetPageRange(false, 1, 3); //打印1至3页
  33. //---------------------常用函数--------------------------------
  34. //document.all.factory.printing.Print(false); //无确认打印,true时打印前需进行确认
  35. //document.all.factory.printing.PrintSetup(); //打印设置
  36. //document.all.factory.printing.Preview(); //打印预览
  37. //document.all.factory.printing.WaitForSpoolingComplete(); //等待上一个打印任务完全送入打印池,在连续无确认打印时非常有用
  38. //document.all.factory.printing.EnumPrinters(index); //枚举已安装的所有打印机,主要用于生成打印机选择功能
  39. }

最后,让所需要打印的页面都引用这个母版页即可。

Web打印控件smsx.cab使用说明的更多相关文章

  1. WEB打印控件Lodop(V6.x)使用说明及样例

    WEB打印控件Lodop(V6.x)使用说明及样例 Lodop是专业WEB控件,用它既可裁剪输出页面内容,又可用程序代码生成复杂打印页. 控件功能强大,却简单易用,所有调用如同JavaScript扩展 ...

  2. Web打印控件

    Lodop是什么? 有人说她是Web打印控件,因为她能打印.在浏览器中以插件的形式出现,用简单一行语句就把整个网页打印出来: 有人说她是打印编程接口,因为她介于浏览器和打印设备之间,是个通道和桥梁,几 ...

  3. 网页WEB打印控件

    网页WEB打印控件制作 在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的 ...

  4. Web打印控件Lodop实现表格物流单的打印

    Web打印控件Lodop实现表格物流单的打印 一.lodop打印预览效果图 LODOP.PRINT_SETUP();打印维护效果图 LODOP.PREVIEW();打印预览图 二.写在前面 最近项目用 ...

  5. C/S架构引用Lodop 如何在C#调用web打印控件Lodop

    lodop是web打印控件,引用安装目录下的ocx文件,可以在c/s架构中使用. 该文件所在路径:C:\Program Files (x86)\MountTaiSoftware\Lodop 有32位和 ...

  6. 在.net Core 使用PDF模板文件生成PDF文件,代替WEB打印控件!

    这几天找WEB打印控件,要么收费的,要么免费的只能在IE里用! 我只想简单的打个标签纸!百度2天,看到一老兄说可以用PDF,然后又开始百度..找到了一篇文章 http://www.jianshu.co ...

  7. WEB打印控件LODOP的使用

    有人说她是Web打印控件,因为她能打印.在浏览器中以插件的形式出现,用简单一行语句就把整个网页打印出来: 有人说她是打印编程接口,因为她介于浏览器和打印设备之间,是个通道和桥梁,几乎能想到的打印控制事 ...

  8. 网页WEB打印控件制作-开放源码

    在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的一件事件,本文将自己开发 ...

  9. WEB打印控件Lodop使用体会

                    控件的使用方法,作者都已经有详细的使用说明供使用者参考. 但是对于打印表格,确实出现一点小问题,如果表格是自然高度,也就是只设置了table的高度,此时是可以正常显示的 ...

随机推荐

  1. unity 3d-Easy Touch 3教程 转

    Easy Touch 教程 转自:http://www.unitymanual.com/thread-31332-1-1.html 1.import “Easy Touch 3”的资源包 2.创建人物 ...

  2. N皇后问题2

    Description Examine the  checkerboard below and note that the six checkers are arranged on the board ...

  3. EXTJS 4.2 资料 控件之Window窗体添加html

    //这里要跳转页面 var subWindow = new Ext.Window({ title: '窗口', width: width, height: height, modal: true,// ...

  4. windows server 2008 r2电脑历史操作记录

    1.看计算机哪天运行过.    在系统盘下的Windows\Tasks文件夹下找到文件SCHEDLGU.TXT. 2.看你最近打开过什么文件(非程序)或者文件夹    开始-->运行--> ...

  5. Qt的gzip模块实现

    一直没找到Qt中方便的gzip模块,于是自己动手,调用zlib模块实现了一份. 目标:  1.gzip的压缩与解压 2.内存中操作 3.方便的Qt接口   实现分析: gzip 压缩算法为 defla ...

  6. 遍历并修改dictionary的值

    var dictionary = clb_Select.Items.Cast<object>().ToDictionary(item => item.ToString(), item ...

  7. dubbo zookeeper模型

    本文摘自dubbo的官方文档,原文请参见: http://alibaba.github.io/dubbo-doc-static/User+Guide-zh.htm#UserGuide-zh-Zooke ...

  8. Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed

    Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed MySQLNonT ...

  9. tomcat部署javaweb项目的三种方式

    一.将项目文件夹或war包直接拷贝到tomcat的webapps下 二.在Tomcat\conf\Catalina\localhost下建立xml文件 修改内容如下<Context path=& ...

  10. linux distribution是什么?

    linux distribution,即Linux发行版,有很多种类,包括Fedora,Ubuntu,Debian,Red Hat,SuSE等,其内核都是差不多的,只是界面设计和功能上各有千秋.