web打印资料

web打印,下面是搜集的资料:
1.可以满足一般情况下的打印:
用document.all.WebBrowser.ExecWB(7,1);只能对整个页面进行打印
先给一个简单实用的方式(可以打印多页,控制分页,隐藏非打印项目)
<!--语言无关 保存成 .HTML 看看-->
<html>
<head>
<title>报表</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}<!--用本样式在打印时隐藏非打印项目-->
.PageNext{page-break-after: always;}<!--控制分页-->
</style>

<style>
.style_td
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.style_tab
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}

</style>

</head>

<body >
<center class="Noprint" >
<p>
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 οnclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 οnclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 οnclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 οnclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>

<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"

class="style_tab">
<tr>
<td colspan="3" class="style_td">第1页</td>
</tr>
<tr>
<td width="29%" class="style_td">&nbsp;</td>
<td width="28%" class="style_td">&nbsp;</td>
<td width="43%" class="style_td">&nbsp;</td>
</tr>
<tr>
<td colspan="3" class="style_td">&nbsp;</td>
</tr>
<tr>
<td colspan="3" class="style_td"><table width="100%" border="0" cellspacing="0"

cellpadding="0">
<tr>
<td width="50%" class="style_td"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
<hr align="center" width="90%" size="1" noshade class="NOPRINT" >
<!--分页-->
<div class="PageNext"></div>
<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"

class="style_tab">
<tr>
<td class="style_td">第2页</td>
</tr>
<tr>
<td class="style_td">看到分页了吧</td>
</tr>
<tr>
<td class="style_td">&nbsp;</td>
</tr>
<tr>
<td class="style_td">&nbsp;</td>
</tr>
<tr>
<td class="style_td"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class="style_td"><p>这样的报表</p>
<p>对一般的要求就够了。</p></td>
<td>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<!--

WebBrowser 控件对象。只要是 win98 以上版本都有。
其实配合“分页样式表”,和 HTML表格 一般的打印都可以实现的。

如果想对 非Windows平台用户使用。
请去掉下面这些:
<center class="Noprint" >
<p>
<!--最主要是这个-->
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=打印 οnclick=document.all.WebBrowser.ExecWB(6,1)>
<input type=button value=直接打印 οnclick=document.all.WebBrowser.ExecWB(6,6)>
<input type=button value=页面设置 οnclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <input type=button value=打印预览 οnclick=document.all.WebBrowser.ExecWB(7,1)>
<br/>
</p>
<hr align="center" width="90%" size="1" noshade>
</center>
-->
2.用scriptx控件实现打印设置
//
//scriptx控件
//技术文档 http://www.meadroid.com/scriptx/docs/printdoc.htm
//
<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"

codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"></object>

控件使用教本:
<script defer>
function SetPrintSettings() {
// -- advanced features ,未曾使用过,有待确认。
factory.printing.SetMarginMeasure(2) // measure margins in inches
factory.SetPageRange(false, 1, 3) // need pages from 1 to 3
factory.printing.printer = "HP DeskJet 870C"
factory.printing.copies = 2
factory.printing.collate = true
factory.printing.paperSize = "A4"
factory.printing.paperSource = "Manual feed"

// -- basic features 使用过
factory.printing.header = "This is MeadCo"
factory.printing.footer = "Advanced Printing by ScriptX"
factory.printing.portrait = false //方向,true
factory.printing.leftMargin = 1.0
factory.printing.topMargin = 1.0
factory.printing.rightMargin = 1.0
factory.printing.bottomMargin = 1.0

factory.printing.Print(false) //直接打印,true ,好像不起作用,总是弹出选择打印机窗口
factory.printing.PageSetup() //打印设置
factory.printing.Preview() //打印预览
}
</script>
下載 ScriptX.cab 存入伺服器

將下列 ScriptX 元件加入 .aspx 網頁中

<object id=factory style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://[your path here]/ScriptX.cab#Version=6,1,432,1">
</object>

[your path here] 為伺服器名稱或 IP 及存入 ScriptX.cab 之路徑

設定列印格式之語法:

<script>
function printWindow( ) {
factory.printing.header = "This is MeadCo"; '頁首
factory.printing.footer = "Printing by ScriptX"; '頁尾
factory.printing.portrait = false; '橫印
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.0;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.0;
factory.printing.Print(false);
}
</script>

設計按鈕執行列印:

<input type="button" name="Print" value="列印" οnclick="printWindow('');">

使用的是网上流传的scriptx.cab来完成打印设置,所以先要下载这个文件。
下载地址:
http://www.meadroid.com/scriptx
,下载完后把该控件加到自己的网页中: <object id="xprint" style="display:none" viewastext

classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="ScriptX.cab#Version=5,60,0,360">
</object>,注意codebase="ScriptX.cab#Version=5,60,0,360"是需要修改的,把“ScriptX.cab”换成自己的存放路径就

可以了。
还是格式问题,先在head中加入<style media="print">.Noprint { DISPLAY: none }</style>,然后设置不需要打印的元

素的格式为Noprint,这样它们就不会再被打印了。
列出可以设置的内容,这些我都已经全部测试通过,大家可以放心使用。
xprint.printing.header = "This is a print test" //页眉
xprint.printing.footer = "test by guanvee from http://blog.donews.com/guanvee" //页脚
xprint.printing.portrait = false //控制横打还是竖打,true为竖打,false为横打
xprint.printing.leftMargin = 1 //左边距
xprint.printing.topMargin = 1 //上边距
xprint.printing.rightMargin = 1 //右边距
xprint.printing.bottomMargin = 1 //下边距
xprint.printing.PageSetup() //弹出打印设置窗口
xprint.printing.Preview() //弹出打印预览窗口
//xprint.printing.Print(true) //直接打印,true:弹出选择打印机窗口,false:直接打印


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值