[转载]使用IE控件与Firefox扩展的页面打印解决方案 – 无心的专栏 – 博客频道 – CSDN.NET.
for IE: MeadCo’s ScriptX ActiveX control
for Firefox: JS Print Setup (extention)
by search “printer ” in firefox addons site, these extentions was found:
CustomPrint : Allows JS-developpers to define specific printer settings to use when printing a page from JavaScript
PrinterMagic : This extension allows web content to control printer settings such as headers, footers, and page orientation.
官方网址:http://www.meadroid.com/scriptx/index.asp
MeadCo’s ScriptX控件有两种使用方式,一种是做为免费版本使用,一种是做为收费版本使用,免费版本支持的功能要少些,不过最重要也是最常用的页面设置,它还 是提供的,因此使用免费版本即可。不过这两个版本用的都是同一个cab文件,只不过在代码设置中有一些不同。
去http://www.meadroid.com/scriptx/sxdownload.asp这里下载smsx.cab文件。
页面调用示例:
<!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>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<object id=factory viewastext style=”display:none” classid=”clsid:1663ed61-23eb-11d2-b92f-008048fdd814″ codebase=”smsx.cab#Version=6,5,439,12″></object>
<title></title>
<style media=”print”>
.noprint {
display:none;
}
</style>
<script type=”text/JavaScript”>
<!–
function SetPrintSettings() {
// — advanced features
//factory.printing.SetMarginMeasure(2); // measure margins in inches
//factory.printing.printer = “HP DeskJet 870C”;
//factory.printing.paperSize = “A4”;
//factory.printing.paperSource = “Manual feed”;
//factory.printing.collate = true;
//factory.printing.copies = 2;
//factory.printing.SetPageRange(false, 1, 3); // need pages from 1 to 3
//注意,如果页面报了JS错误,可以先将以上advanced features全部去掉,只留下面的basic features,这里我将上面的全部注释掉
// — basic features
factory.printing.header = “”;
factory.printing.footer = “”;
factory.printing.portrait = false;
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.0;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.0;
}
function Print(frame) {
factory.printing.Print(true, frame) // print with prompt
}
//–>
</script>
</head>
<body onload=”SetPrintSettings()”>
<table border=”1″ width=”100%”>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>d</td>
</tr>
</table>
<center class=”noprint”>
<input type=button value=”打印本页” onclick=”factory.printing.print(false)”>
<input type=button value=”页面设置” onclick=”factory.printing.PageSetup()”>
<input type=button value=”打印预览” onclick=”factory.printing.Preview()”>
</center>
</body>
</html>
官方说明文档:http://www.meadroid.com/scriptx/docs/printdoc.asp,建议看看这个。