aspnet打印 设置(页脚 一些数据显示在打印页的最下面)

打印使用js方法 window.print();

下面是asp.net页面代码

打印出来的效果'divFoot'数据显示在打印页的最下方

在a4纸打印测试通过。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Print1.aspx.cs" Inherits="AspTest.Web.Printl" %>
<!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 runat="server">
    <title></title>
    <style type="text/css" media="print">
        .noprint{display:none;}
    </style>
        <script type="text/javascript" >
       function SetPrint() {
//           style = "display: block; position: fixed; bottom: 0; 750px; text-align:center;"
           var div = document.getElementById('divFoot'); //.bgColor = '#ff0000'
           div.style.display = "block";
           div.style.position = "fixed";
           div.style.bottom = 0;
           div.style.width="750px";
           div.style.textAlign = "center";
       }
       function SetNoPrint() {
           var div = document.getElementById('divFoot'); //.bgColor = '#ff0000'
           div.style.display = "block";
           div.style.position = "relative";
           div.style.bottom = 0;
           div.style.width = "750px";
           div.style.textAlign = "center";
       }
       function CanPrint() {
           SetPrint();
           window.print();
           SetNoPrint();
       }
   </script>
</head>
<body>
<input type="button" value="打印" class="noprint" style="font-size:14px;line-height:20px;height:30px;width:80px;text-align:center;margin-left:500px;margin-bottom:20px;padding:5px;" onclick="CanPrint();" />
    <form id="form1" runat="server">
    <div id="main"  >
        <div id="logo"><img src="images/logo.png" alt="注册商标"/></div>
        <div id="title_zh">采购订单</div>
        <div id="title_en">Purchase Contract</div>
        <div style="float:right;margin-right:100px;">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td><div class="t1">采购订单号:</div></td>
                    <td style="border-bottom:1px solid"><span class="t2"><%=this.pbCode %></span></td>
                </tr>
                <tr>
                    <td><div class="t1">采购日期:</div></td>
                    <td style="border-bottom:1px solid"><span class="t2"><%=this.pbTime %></span></td>
                </tr>
            </table>
        </div>
       <div style="clear:both"></div>
       <div style="margin:0 auto;width:80%;padding:20px 0;">
           <table border="0" cellpadding="0" cellspacing="0" id="info">
                <tr>
                    <td><span>收件人(Attn):</span><span><%=this.attn %></span></td>
                    <td>发件人(Send):张三<span></span></td>
                </tr>
                <tr>
                    <td><span>收件单位:</span><span><%=this.attp %></span></td>
                    <td>发件单位:北京上海表厂<span></span></td>
                </tr>
                <tr>
                    <td><span>收件号码(FAX):</span><span><%=this.fax %></span></td>
                    <td>发件号码(FAX):010-55555555555<span></span></td>
                </tr>
            </table>
       </div>
       
        <div style="text-align:left;margin-left:80px;font-size:16px;font-weight:bold;">采购明细</div>
        <div>
            <asp:GridView ID="gDetails" runat="server" OnRowDataBound="gDetails_RowDataBound" AutoGenerateColumns="false" CssClass="details" CellPadding="5" Width="80%">
            <Columns> 
                <asp:BoundField HeaderText="序号" />
                <asp:BoundField DataField="pdMaterialName" HeaderText="品名" /> 
                <asp:BoundField DataField="pdCount" HeaderText="数量" /> 
                <asp:BoundField DataField="unit" HeaderText="单位" /> 
                <asp:BoundField DataField="bzCount" HeaderText="包装数量" /> 
                <asp:BoundField DataField="pdTime" HeaderText="订购日期" /> 
                <asp:BoundField DataField="note" HeaderText="备注" /> 
            </Columns> 
            <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /> 
            </asp:GridView>
            <div style="font-weight:bold;margin-bottom:40px;margin-top:10px">合计数据量:<%=this.sumCount %></div>
        </div>
            <div class="t3">收到订单请确认并安排发货,谢谢!</div>
            <div class="t3">顺祝商祺!</div>
        
             <div   id="divFoot">
           
          
             <div style="margin:0 auto;width:80%;padding:20px 0;">
               <table border="0" cellpadding="0" cellspacing="0" id="stamp">
                    <tr>
                        <td class="t5">销售方</td>
                        <td class="t6">购货方:上海表厂</td>
                    </tr>
                    <tr>
                        <td class="t7">(签字盖章确认)</td>
                        <td class="t8"><%=DateTime.Now.ToString("yyyy-MM-dd") %><span></span></td>
                    </tr>
                </table>
           </div>
            
             <div id="footer" >
            <table border="0" cellpadding="0" cellspacing="0" id="foot">
                    <tr>
                        <td>地址:上海市北京街3252号</td>
                        <td >邮编:101708</td>
                    </tr>
                    <tr>
                        <td>电话/传真:010-599999999</td>
                        <td>网址:http://www.123.com/</td>
                    </tr>
                </table>
            </div>
             </div>
    </div>
  
    
    </form>
</body>
</html>
 

下面是css

body 
{
    background:#fff;
    text-align:center;
    font-family:"宋体";
}
#main{width:750px;margin:0 auto;}
#logo{text-align:left;margin:10px 15px;}
#title_zh{font-family:"黑体";font-size:24px;font-weight:bold;letter-spacing:1em;margin:10px 0;}
#title_en{font-family:Times New Roman;font-size:16px;font-weight:bold;word-spacing:10px;margin:5px 0;margin-left:-1em;}
.t1{font-size:10px;font-weight:bold;text-align:left;}
.t2{font-family:Times New Roman;font-size:10px;font-weight:bold;text-align:left;}
#info,#stamp,#foot{width:100%;font-size:14px;}
#info td{width:50%;border-bottom:1px solid;height:25px;line-height:25px;font-size:14px;text-align:left;}
.details{margin:0 auto;margin-top:10px;}
.t3{font-size:14px;text-align:left;height:25px;line-height:25px;margin-left:80px;}
.t4{float:left;width:50%;}
#stamp td{width:50%;height:40px;line-height:40px;}
.t5,.t7{text-align:left;}
.t6,.t8{text-align:right;}
.t5,.t6{font-size:16px;font-family:"黑体";font-weight:bold;}
.t8{font-weight:bold;font-family:Times New Roman;}
 
#footer{padding-top:20px;border-top:1px solid;margin:0 auto;width:80%;}
#foot td{width:50%;text-align:left;font-size:12px;padding-left:20px;}
 
原文地址:https://www.cnblogs.com/z_lb/p/2339111.html