无为清净楼资源网 Design By www.qnjia.com

过程很简单:

首先在asp.net页面中设定开始打印和结束打印的标记,为了确保该标记不在网页浏览时显示,我们采用"<!-- HTML注释 -->"的方式。比如:<!--startprint-->和<!--endprint-->。

接着写相关的JavaScript代码,具体代码见后。

如果不想打印按钮也被打印出来,注意将打印按钮包含在<!--startprint-->和<!--endprint-->之外。

相关代码:
复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AppealPrint.aspx.cs" Inherits="Appeal.AppealPrint"

MasterPageFile="MasterPage.master" Title="诉求打印" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="server">
<!--startprint-->
<style type="text/css">
body,table{
    font-size:12px;
}
table{
    table-layout:fixed;
    empty-cells:show;
    border-collapse: collapse;
    margin:0 auto;
}
td{
    height:20px;
}
h1,h2,h3{
    font-size:12px;
    margin:0;
    padding:0;
}


table{
    border:1px solid #cad9ea;
    color:#666;
}
table th{
    height:30px;
}
table td,table th{
    border:1px solid #cad9ea;
    padding:0 1em 0;
}
table tr{
    background-color:#f5fafe;
}
</style>
   <table class="border" cellspacing="0" cellpadding="2" style="margin: 0px auto; width: 98%;border:1px solid;border-collapse:collapse;" id="TabBtnPrint">
    <tbody>
        <tr align="center">
            <td class="title"><strong>诉 求 信 息</strong></td>
        </tr>
        <tr>
            <td style="height: 25px">
            <table cellspacing="1" cellpadding="2" style="margin: 0px auto; width: 100%;border-collapse:collapse;">
                <tbody>
                    <tr class="tdbg">
                         <td width="30%" align="right" nowrap="nowrap">诉求主题:</td>
                         <td colspan="3">
                             <asp:Label ID="lblEditTitle" runat="server" Text="Label"></asp:Label>
                         </td>
                    </tr>
                    <tr class="tdbg">
                        <td align="right" width="30%" nowrap="nowrap">诉求类型:</td>
                        <td  colspan="3">
                              <asp:Label ID="lblAppealCategory" runat="server" Text=""/>
                        </td>
                    </tr>
                    <tr class="tdbg">
                        <td align="right" width="30%" nowrap="nowrap">诉求当前状态:</td>
                        <td colspan="3">
                              <asp:Label ID="LblStatus" runat="server" Text="Label"/>
                        </td>
                    </tr>
                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">诉求性质:</td>
                        <td style="width: 15%"><asp:Label ID="lblAppealNature" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap">被投诉人姓名:</td>
                        <td style="width: 30%"><asp:Label ID="lblBeAppealName" runat="server" Text="Label"/></td>
                    </tr>


                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">被投诉人地址:</td>
                        <td style="width: 15%"><asp:Label ID="lblBeAppealAddress" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap">投诉人:</td>
                        <td style="width: 30%"><asp:Label ID="lblUserName" runat="server" Text="Label"/></td>
                    </tr>


                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">诉求信息是否保密:</td>
                        <td style="width: 15%"><asp:Label ID="lblIsSecret" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap">管理员是否同意公开:</td>
                        <td style="width: 30%" align="right"><asp:Label ID="lblAdminIsPublic" runat="server" Text="Label"/></td>
                    </tr>


                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">浏览数:</td>
                        <td style="width: 15%"><asp:Label ID="lblHits" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap">回复数:</td>
                        <td style="width: 30%"><asp:Label ID="lblReply" runat="server" Text="Label"/></td>
                    </tr> 

                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">归档:</td>
                        <td style="width: 15%"><asp:Label ID="lblCategory" runat="server" Text=""/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap">诉求提交时间:</td>
                        <td style="width: 30%"><asp:Label ID="lblCreateTime" runat="server" Text="Label"/></td>
                    </tr>


                    <tr class="tdbg">
                        <td align="right" style="width: 30%" nowrap="nowrap">诉求所在地域:</td>
                        <td colspan="3"><asp:Label ID="lblRegion" runat="server" Text=""></asp:Label></td>
                    </tr>
                    <tr class="tdbg">
                        <td colspan="4"><asp:Label ID="Label2" runat="server" Text=""/></td>
                    </tr>
                    <tr class="tdbg">
                        <td colspan="4" align="left" valign="top" nowrap="nowrap">诉求内容:</td>
                    </tr>
                    <tr class="tdbg">
                        <td colspan="4" align="left" valign="top">
                            <pe:ExtendedLiteral ID="LtrEditContent" runat="server" HtmlEncode="false"/>
                        </td>
                    </tr>
                </tbody>
            </table>
            </td>
        </tr>
    </tbody>
</table>
<!--endprint-->
   <br />
    <div id="divBtnPrint" style="text-align:center">
        <input id="BtnPrint" type="button" value="打 印…" onclick="doPrint();" />
    </div>
    <br />
 <script type="text/javascript">

<!--

     function doPrint(){
        bdhtml = window.document.body.innerHTML;
        sprnstr = "<!--startprint-->";
        eprnstr = "<!--endprint-->";
        prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
        prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML =  prnhtml;
        var obj = window.document.body;
        doZoom(obj, 18); //放大打印
        window.print();
    }

    function doZoom(artibody, size) {
        if (!artibody)
        {
          return;
        }
          setChildNodesByCurrentNode(artibody,size);
    }

    function setChildNodesByCurrentNode(node,size) {
        for(var i=0; i < node.childNodes.length; i++) {
            var artibodyChild = node.childNodes[i];
            if (artibodyChild.nodeType == 1) {
                artibodyChild.className="";
                artibodyChild.style.fontSize = size + 'px';
                artibodyChild.style.fontFamily = '仿宋_GB2312,宋体,"Times New Roman",Georgia,serif';
                artibodyChild.style.fontWeight = 900;
                if(artibodyChild.childNodes.length>0) {
                    setChildNodesByCurrentNode(artibodyChild,size);
                }
            }
         }
      }

-->

 </script>
</asp:Content>

观察上面代码可以看出,打印时,window.document.body.innerHTML 被重新赋值成设定需要打印的网页部分的代码(这里是 prnhtml),然后通过递归方式调用setChildNodesByCurrentNode(artibody,size)更改相关子节点的样式,以达到全部更换相关字体大小及样式设置的目的。

标签:
.net,按需打印

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。