【问题标题】:How to make default landscape print using javascript/Extjs?如何使用 javascript/Extjs 进行默认横向打印?
【发布时间】:2013-06-26 06:30:19
【问题描述】:

我已经使用 Extjs 4.1 完成了应用程序,通过在新窗口中创建 XTemplte 打开来实现打印功能。打印工作非常好。一旦我点击打印,它将默认以纵向模式打开,而不是这个默认情况下如何以横向模式打开打印?非常感谢。谢谢。

这是我的代码:

if (Ext.isChrome) {
            newWin= window.open();
            newWin.document.write('<p style="color: #003366;font-weight:bold;font-size:30px; text-align: center">'+titleName+'</p>'+'<p style="color: #003366;font-weight:bold;font-size:10px; text-align: left">'+filterlblInfo+'</p>'+this.generateHTML(GridViewId));            
            newWin.document.close();
            newWin.focus();
            newWin.print();
            newWin.close();
            newWin='';
        }
        else{
            var win = window.open('', name);
            win.document.write('<p style="color: #003366;font-weight:bold;font-size:30px; text-align: center">'+titleName+'Currency Type:'+currencyType+'</p>'+'<p style="color: #003366;font-weight:bold;font-size:10px; text-align: left">'+filterlblInfo+'</p>'+this.generateHTML(GridViewId));
            setTimeout(function() {
                win.document.close();
                win.print();
                win.close();
            }, 1000);
        }



generateHTML: function(component) {
        return new Ext.XTemplate(
            '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
            '<html>',
            '<head>',
            '<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />',
            '<meta http-equiv="X-UA-Compatible" content="IE=9">',
            '<style type="text/css" media="print">',
            '@page { size: landscape; }',
            '</style>',            
            '<link href="resources/css/default/printer.css" rel="stylesheet" type="text/css" media="screen,print" />',           
            '</head>',
            '<body>',
            this.generateBody(component),
            '</body>',
            '</html>'
            ).apply(this.prepareData(component));
    }

【问题讨论】:

    标签: javascript css browser extjs4.1 extjs-mvc


    【解决方案1】:

    您在调用window.open 时指定窗口的高度和宽度,如下所示:

    var win = window.open('', name, "height=500,width=1000");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-04
      • 2010-09-09
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-02
      相关资源
      最近更新 更多