Web打印中使用ScriptX做页面设置

来源:互联网 发布:微信无获取摄像头数据 编辑:程序博客网 时间:2024/05/01 21:40

使Web打印时页面的设置,比如页眉、页脚、页边距等,可以使用ScriptX中的免费功能实现。相关说明文档:http://www.meadroid.com/scriptx/docs/printdoc.htm

 

需要下载smsx.cab文件

下载以后是一个smsx.cab文件,把它放到你的应用目录下,例如/common/smsx.cab。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>PringPage</title>

    <script language="javascript" type="text/javascript">
 function OpenPrintPreview()
 {
  document.all("divButton").style.display = "none";
  factory.printing.header = "";
  factory.printing.footer = "";
  //上边距
  factory.printing.topMargin = 27;
  //下边距
  factory.printing.bottomMargin = 27;
  //左边距
  factory.printing.leftMargin = 25.4;
  //右边据
  factory.printing.rightMargin = 25.4;
  factory.printing.portrait = true;
  factory.printing.Preview();
  document.all("divButton").style.display = "";
  
  return false;
 }
 function OpenPrint()
 {
  document.all("divButton").style.display = "none";
  factory.printing.header = "";
  factory.printing.footer = "";
  //上边距
  factory.printing.topMargin = 27;
  //下边距
  factory.printing.bottomMargin = 27;
  //左边距
  factory.printing.leftMargin = 25.4;
  //右边据
  factory.printing.rightMargin = 25.4;
  factory.printing.portrait = true;
  factory.printing.Print(false);
  document.all("divButton").style.display = "";

  return false;
 }
    function OnReturn()
    {
        window.parent.right.location = document.all("txtHiddenPage").value;
        return false;
    }
    </script>

</head>
<body>
    <object id="factory" style="display: none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
        codebase="Common/smsx.cab" viewastext>
    </object>
    <form id="form1" runat="server">
    <div id="divButton">
        <asp:Button ID="btnPrintView" runat="server" Text="预览" /><asp:Button ID="btnPrint"
            runat="server" Text="打印" /><asp:Button ID="btnReturn" runat="server" Text="返回" /><input
                id="txtHiddenPage" type="hidden" runat="server" />
    </div>
    <div>
        <div id="divPrint" runat="server">
        </div>
    </div>
    </form>
</body>
</html> 

 

    factory.printing.Print(true),这里设置成true或false,我没有发现有什么不同的效果。它的原意是直接打印。

  factory.printing.Print(true, idFrame),第一个参数同上,第二个参数是目标框架的name。

  factory.printing.PageSetup()是调出页面设置窗口。

  factory.printing.Preview()是调出页面预览窗口。

原创粉丝点击