惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - CsharpFish

Sql2005 PIVOT运算符的操作 Lodop使用之WEB套打程序开发 jquery插件treeTable Asp.net 后台添加CSS、JS、Meta标签的写法 DataGridView拖动换行 CodeSmith----SchemaExplorer类结构详细介绍 - CsharpFish - 博客园 js request 应用举例 背景图片随窗口拉伸 js日期控件-梅花雨 利用VML生成柱状图和饼图 js操作Table绑定DataSet 小小个人消费管理系统(已完善) GridView分页用户自定义控件 DbType与OleDbType 添加修改后返回刷新查询页面 asp.net页面传值(transfer Context.Handler) GridViev皮肤(Skin&CSS) JavaScript验证控件并阻止表单提交 GridView自定义分页存储过程
WebBrowser网页局部打印 - CsharpFish - 博客园
CsharpFish · 2008-12-04 · via 博客园 - CsharpFish

 首先建立一个模板页:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="PrintMasterPage.master.cs"
    Inherits
="PrintMasterPage" 
%>
<!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>
    
<object id='WebBrowser' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'>
    
</object>
    
<link rel="stylesheet" href="css/show.css" type="text/css" />

<script language="javascript" type="text/javascript">
//获取单个对象
function getObj(id)
{
    
return
 document.getElementById(id);
}

//获取对象组
function getObjs(name)
{
    
return
 document.getElementsByTagName(name);
}

//打印文档
function printDoc()
{
    
var objs=getObjs('div'
);
    
var length=
objs.length;
    
for(var i=0;i<length;i++
)
    
{
        
if(objs[i].print==1
)
        
{
            p
=
objs[i].parentNode;
            p.style.visibility
='visible'
;
            
if(p.childNodes.length>1
)
            
{
                
for(var j=0;j<p.childNodes.length;j++
)
                
{
                    
if(p.childNodes[j].print!=1&&p.childNodes[j].style!=
undefined)
                    
{
                        p.childNodes[j].style.visibility
='hidden'
;
                    }

                }

            }

            objs[i].visibility
='visible';
        }

    }

    PageSetup_Null();
    
//InitPrint();
    getObj('WebBrowser').ExecWB(7,1);
}

</script>

<script language="JavaScript" type="text/javascript">   
var
 HKEY_Root,HKEY_Path,HKEY_Key; 
HKEY_Root
="HKEY_CURRENT_USER"

HKEY_Path
="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"

//设置网页打印的页眉页脚为空 

function PageSetup_Null() 

 
try
 
 

  
var Wsh=new ActiveXObject("WScript.Shell"
); 
  HKEY_Key
="header"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""
); 
  HKEY_Key
="footer"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""
); 
  HKEY_Key
="margin_bottom"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"2"
); 
  HKEY_Key
="margin_left"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"2"
); 
  HKEY_Key
="margin_right"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"2"
); 
  HKEY_Key
="margin_top"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"2"
); 
 }
 
 
catch(e)
{
    
//alert(e);

 }
 
}
 
//设置网页打印的页眉页脚为默认值 

function  PageSetup_Default() 
{   
 
try
 
 

  
var Wsh=new ActiveXObject("WScript.Shell"
); 
  HKEY_Key
="header"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"
); 
  HKEY_Key
="footer"

  Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&u&b&d"
); 
 }
 
 
catch(e){}
 
}
 
    
</script>

<style type="text/css" media="print">

body
{visibility:hidden;}
.print
{visibility:visible;}

</style>

<style type="text/css" media="screen">

body
{visibility:visible;
    margin-top
: 0px;
    margin-left
:0px;
}

.control
{
    margin
: 0px;
    padding
: 0px;
    width
: 590px;
}


</style>
</head>
<body>
    
<form id="form1" runat="server">
        
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
</asp:ContentPlaceHolder>
        
<div align="center">
            
<table width="100%">
                
<tr>
                    
<td align="center">
                        
<input id="btnPrint" type="button" value=" 打 印 " onclick="javascript:printDoc();" class="button" />
                        
<input type="button" id="btnSet" class="button" value="页面设置" onclick="javascript:document.all.WebBrowser.ExecWB(8,1)" />
                        
<input type="button" id="btnClose" onclick="javascript:document.all.WebBrowser.ExecWB(45,1);" value=" 关 闭 "  class="button" />
                    
</td>
                
</tr>
            
</table>
        
</div>
    
</form>
</body>
</html>

然后在子页面中设置给要打印的DIV添加一个(print="1")的属性就可以了。