How can I change the orientation of a document dynamically before printing
I can get the priting dialogue to come up with javascript window.print();
but I can't change it to landscape. is it possible with jquery or any way?
edit
if not,开发者_JS百科 is there a work around?
I have found a solution for IE6 but not IE7 or 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()">
I think you should let the browser handle the printing and just set a CSS specific for it.
<link rel="stylesheet" type="text/css" href="style.css" media="print" />
This is a printer software specific issue, you won't be able to do this without significant hackery with 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>
精彩评论