asp. of prints the part of the implementation code you need to print

  • 2020-06-07 04:24:52
  • OfStack

The process is simple:

First, set the start and end print tags in asp.net page. To ensure that the tags are not displayed during web browsing, we use" < ! -- HTML notes > ". Such as: < !--startprint-- > and < !--endprint-- > .

Then write the relevant JavaScript code, see the code below.

If you do not want the print button to be printed, note that the print button is included in the < !--startprint-- > and < !--endprint-- > Outside.

Related code:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AppealPrint.aspx.cs" Inherits="Appeal.AppealPrint"
MasterPageFile="MasterPage.master" Title=" Appeal to print " %>
<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> v.   o   The letter   Interest rates </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"> Appeal theme: </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"> Type of appeal: </td>
                        <td  colspan="3">
                              <asp:Label ID="lblAppealCategory" runat="server" Text=""/>
                        </td>
                    </tr>
                    <tr class="tdbg">
                        <td align="right" width="30%" nowrap="nowrap"> Appeal current status: </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"> Nature of appeal: </td>
                        <td style="width: 15%"><asp:Label ID="lblAppealNature" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap"> Name of respondent: </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"> Address of respondent: </td>
                        <td style="width: 15%"><asp:Label ID="lblBeAppealAddress" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap"> The complainant: </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"> Whether the requested information is confidential: </td>
                        <td style="width: 15%"><asp:Label ID="lblIsSecret" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap"> Whether the administrator agrees to disclose: </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"> Browse the number: </td>
                        <td style="width: 15%"><asp:Label ID="lblHits" runat="server" Text="Label"/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap"> Reply: </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"> Archive: </td>
                        <td style="width: 15%"><asp:Label ID="lblCategory" runat="server" Text=""/></td>
                        <td align="right" style="width: 25%" nowrap="nowrap"> Submission time: </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"> Location of appeal: </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"> Content of appeal: </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=" play   Printing... " 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); // Enlarge print 
        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 = ' Imitation song dynasty style typeface _GB2312, Song typeface ,"Times New Roman",Georgia,serif';
                artibodyChild.style.fontWeight = 900;
                if(artibodyChild.childNodes.length>0) {
                    setChildNodesByCurrentNode(artibodyChild,size);
                }
            }
         }
      }
-->
 </script>
</asp:Content>

Observe the code above you can see, print, window. document. body. innerHTML assignment was to be a need to print the web part of the code (this is prnhtml), and then by recursively call setChildNodesByCurrentNode (artibody size) change the style of the related child nodes, all change the font size and style in order to achieve the purpose.


Related articles: