WebBrowser横向打印自动设置页边距

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”PrintPage.aspx.cs” Inherits=”Demo.Web.PrintPage” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1” runat=”server”>
    <title>打印单</title>
    <link href=”../CSS/css-main.css” type=”text/css” rel=”stylesheet” media=”all” />
    <script type=”text/javascript”>
//注册表的网页打印路径
var hkey_root=”HKEY_CURRENT_USER” ;
var hkey_path=”\\Software\\Microsoft\\Internet Explorer\\PageSetup\\”;
var hkey_key;    
    
        //打印指定区域
        function DoPrint()
        {   
     //直接调用WebBrowser的打印,要打印预览的话是ExecWB(7,1)
     document.all.WebBrowser.ExecWB(6,1);
        }
     
//设置纸张方向
function SetupLandscape()
{
     try{
   var wsShell= new ActiveXObject(“WScript.Shell”);
   //打印页面的Menubar必须可见,此操作类似按键盘上的Alt+F+U也就是 调出页面设置对话框
   wsShell.sendKeys(‘%fu’);
   //此操作类似按键盘上的Alt+A也就是 设置横向打印
   wsShell.sendKeys(‘%a’);
   //此操作类似按键盘上的回车 页面设置对话框的默认焦点在 确定上 所以直接确定
   wsShell.sendKeys(‘{ENTER}’);
     }
     catch(e){}
}

//设置默认的页眉页脚
function SetupPage()
{
     try{
   var RegWsh = new ActiveXObject(“WScript.Shell”);
   hkey_key=”header”
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”&w&b页码,&p/&P”)
   hkey_key=”footer”
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”&b&d”) //去掉了&u 因为我不想显示当前打印页的网址
   hkey_key=”margin_bottom”;
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”0.39”); //0.39相当于把页面设置里面的边距设置为10
   hkey_key=”margin_left”;
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”0.39”);
   hkey_key=”margin_right”;
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”0.39”);
   hkey_key=”margin_top”;
   RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,”0.39”);
     }
     catch(e){}
}

setTimeout(“SetupLandscape()”,1000);
setTimeout(“SetupPage()”,2000);
setTimeout(“DoPrint()”,3000);
    </script>

</head>
<body>
    <form id=”form1” runat=”server” enctype=”multipart/form-data”>
        <OBJECT id=”WebBrowser” height=”0” width=”0” classid=”CLSID:8856F961-340A-11D0-A96B-00C04FD705A2” VIEWASTEXT ></OBJECT >
        <table width=”100%”>
            <tr><td>要打印的内容</td></tr>
        </table>
    </form>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值