如何在打印前动态更改文档的方向?

How can I change the orientation of a document dynamically before printing

本文关键字:文档 方向 动态 打印      更新时间:2023-09-26

我可以得到的打印对话框拿出javascript window.print();,但我不能改变它的景观。这是可能的与jquery或任何方式?

编辑

如果没有,是否有解决方法?

我找到了IE6的解决方案,但不是IE7或Firefox

<script type="text/javascript">
var shell;
function SetPrintProperties() {
try {
shell = new ActiveXObject("WScript.Shell");
shell.SendKeys("%fu");
window.setTimeout("javascript:SetPaperSize();", 1200);
window.setTimeout("javascript:setLandScape();", 2000);
} catch (e) {
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}
function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}
function setLandScape() {
shell.sendKeys("%fp");
window.print();
}
</script>
<body onload="SetPrintProperties()">

我认为你应该让浏览器来处理打印,并为它设置一个特定的CSS。

<link rel="stylesheet" type="text/css" href="style.css" media="print" />

这是打印机软件特有的问题,如果没有javascript的重大黑客攻击,您将无法做到这一点。


<script language="javascript" type="text/javascript">
var shell = new ActiveXObject("WScript.Shell");
function SetPrintProperties() {
try {
window.setTimeout("BLOCKED SCRIPTshell.SendKeys('%fu');",1);
window.setTimeout("BLOCKED SCRIPTSetPaperSize();", 1);
print();
} catch (e) {
alert ("An exception occured: " + e + "'nCode is: " + e.number + "'nDescription is: " + e.description);
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}
function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}
SetPrintProperties();
</script>