试了很多办法,包括修改注册表的,涉及到安全权限,还是用这个插件比较靠谱。
到官方下载最新版的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=gb2312" />
<title>WEB打印示例</title>
</head>
<body>
<!--smsx.cab下载:http://www.meadroid.com/scriptx/-->
<object id="factory" viewastext style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://[HOST]/print/smsx.cab#Version=6,6,440,26">
</object>
<script language="javascript">
function window.onload() {
if (!factory.object) {
alert("打印控件没有正确安装!");
return;
} else {
// -- advanced features
//factory.printing.SetMarginMeasure(2); // measure margins in inches
//factory.printing.printer = "HP DeskJet 870C";
//factory.printing.paperSize = "A4";
//factory.printing.paperSource = "";
//factory.printing.collate = true;
//factory.printing.copies = 2;
//factory.printing.SetPageRange(false, 1, 3); // need pages from 1 to 3
// -- basic features
factory.printing.header = "";
factory.printing.footer = "";
factory.printing.portrait = true;//true正向,false横向
factory.printing.leftMargin = 0.75;//页边距
factory.printing.topMargin = 0.75;
factory.printing.rightMargin = 0.75;
factory.printing.bottomMargin = 0.75;
}
}
function p_print(frame) {
factory.printing.Print(true, frame) // print with prompt
}
</script>
<!--打印示例-->
<p>web打印示例</p>
<p>web打印示例</p>
<p>
<input type="button" name="Submit2" value="打印设置" οnclick="factory.printing.PageSetup();"/>
<input type="button" name="Submit" value="打印预览" οnclick="factory.printing.Preview();" />
<input type="button" name="Submit3" value="打印" οnclick="javascript:p_print();" />
</p>
</body>
</html>