佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > asp.net中的“按需打印”(打印你需要打印的部分) 實(shí)現(xiàn)代碼

asp.net中的“按需打印”(打印你需要打印的部分) 實(shí)現(xiàn)代碼

熱門標(biāo)簽:人工智能 電商新玩法 客戶服務(wù) 百度AI接口 國美全國運(yùn)營中心 科大訊飛語音識(shí)別系統(tǒng) 網(wǎng)站排名優(yōu)化 電銷業(yè)務(wù)

過程很簡單:

首先在asp.net頁面中設(shè)定開始打印和結(jié)束打印的標(biāo)記,為了確保該標(biāo)記不在網(wǎng)頁瀏覽時(shí)顯示,我們采用"!-- HTML注釋 -->"的方式。比如:!--startprint-->和!--endprint-->。

接著寫相關(guān)的JavaScript代碼,具體代碼見后。

如果不想打印按鈕也被打印出來,注意將打印按鈕包含在!--startprint-->和!--endprint-->之外。

相關(guān)代碼:

復(fù)制代碼 代碼如下:

%@ 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">訴求當(dāng)前狀態(tài):/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">訴求性質(zhì):/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">瀏覽數(shù):/td>
                        td style="width: 15%">asp:Label ID="lblHits" runat="server" Text="Label"/>/td>
                        td align="right" style="width: 25%" nowrap="nowrap">回復(fù)數(shù):/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">訴求提交時(shí)間:/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">訴求內(nèi)容:/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>


觀察上面代碼可以看出,打印時(shí),window.document.body.innerHTML 被重新賦值成設(shè)定需要打印的網(wǎng)頁部分的代碼(這里是 prnhtml),然后通過遞歸方式調(diào)用setChildNodesByCurrentNode(artibody,size)更改相關(guān)子節(jié)點(diǎn)的樣式,以達(dá)到全部更換相關(guān)字體大小及樣式設(shè)置的目的。

您可能感興趣的文章:
  • 關(guān)于ASP.NET頁面打印技術(shù)的常用方法總結(jié)
  • ASP.NET網(wǎng)頁打印(只打印相關(guān)內(nèi)容/自寫功能)
  • asp.net 打印控件使用方法
  • 代碼實(shí)現(xiàn)打印功能(asp.net+javascript)
  • ASP.NET 水晶報(bào)表打印功能實(shí)現(xiàn)代碼
  • asp.net css控制打印功能方法實(shí)例

標(biāo)簽:攀枝花 POS機(jī) 咸寧 廈門 拉薩 南平 益陽 棗莊

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net中的“按需打印”(打印你需要打印的部分) 實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    靖宇县| 孙吴县| 平南县| 岗巴县| 神农架林区| 陆良县| 连江县| 长沙县| 若羌县| 雷州市| 甘南县| 康马县| 顺义区| 赤峰市| 渝中区| 平罗县| 怀宁县| 醴陵市| 安塞县| 德令哈市| 齐齐哈尔市| 正安县| 毕节市| 台东市| 沙河市| 黔西| 民勤县| 光泽县| 宁强县| 河源市| 绥化市| 丘北县| 韶山市| 建水县| 乌兰察布市| 榆树市| 东兴市| 塔城市| 西畴县| 沾益县| 登封市|