【问题标题】:How can I change the orientation of a document dynamically before printing如何在打印前动态更改文档的方向
【发布时间】:2011-08-01 16:00:04
【问题描述】:

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

编辑

如果没有,有解决办法吗?

【问题讨论】:

    标签: javascript jquery css printing


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我认为您应该让浏览器处理打印并为其设置特定的 CSS。

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

      【讨论】:

      • 这是做什么的?是不是直接放在head标签里,浏览器在打印的时候就知道页面是横向还是纵向?
      【解决方案3】:

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

      【讨论】:

        【解决方案4】:
        <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>

        【讨论】:

        • 它不起作用。它说预期的';'在第 1 行,但我没有看到任何半冒号任务。您在哪个浏览器上尝试过?这也适用于任何打印机软件吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-18
        • 2018-03-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多