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

时间:2011-08-01 16:00:04

标签: javascript jquery css printing

我可以通过javascript window.print();获取打印对话框,但我无法将其更改为横向。有可能用jquery或任何方式吗?

修改

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

4 个答案:

答案 0 :(得分:2)

我找到了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()">

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

这是一个特定于打印机软件的问题,如果没有javascript的重大问题,你将无法做到这一点。

答案 3 :(得分:0)


<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>