Window.print()将默认副本设置为2 [英] Window.print() sets default copies to 2

查看:151
本文介绍了Window.print()将默认副本设置为2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,通过单击一个按钮,将打开打印机对话框,其打印份数设置为2,而不是默认的份数1.

I have a requirement that by clicking on a button, the printer dialog will open with the number of copies set to 2 instead of the default number 1.

推荐答案

不,不能将纯javascript与window.print()一起使用.

No it is not possible using pure javascript with window.print().

但是,如果您愿意使用Java Applet,请查看 qz-print aka jzebra .我已经在过去的一些项目中亲自使用了此功能,以实现一些高级打印要求,并且效果非常令人满意.看看他们的printHTML()方法

However, if you are open to using Java Applet, take a look at qz-print aka jzebra. I have personally used this in some past projects for some advance printing requirements and the result is very satisfying. Take a look at their printHTML() method

***************************************************************************
    * Prototype function for printing plain HTML 1.0 to a PostScript capable 
    * printer.  Not to be used in combination with raw printers.
    * Usage:
    *    qz.appendHTML('<h1>Hello world!</h1>');
    *    qz.printPS();
    ***************************************************************************/ 
    function printHTML() {
        if (notReady()) { return; }

        // Preserve formatting for white spaces, etc.
        var colA = fixHTML('<h2>*  QZ Print Plugin HTML Printing  *</h2>');
        colA = colA + '<color=red>Version:</color> ' + qz.getVersion() + '<br />';
        colA = colA + '<color=red>Visit:</color> http://code.google.com/p/jzebra';

        // HTML image
        var colB = '<img src="' + getPath() + 'img/image_sample.png">';

                //qz.setCopies(3);
        qz.setCopies(parseInt(document.getElementById("copies").value));

        // Append our image (only one image can be appended per print)
        qz.appendHTML('<html><table face="monospace" border="1px"><tr height="6cm">' + 
        '<td valign="top">' + colA + '</td>' + 
        '<td valign="top">' + colB + '</td>' + 
        '</tr></table></html>');

        qz.printHTML();
    }

当然,如果您只想打印2份,这可能会被彻底杀死并且实施起来太复杂.但是我不知道有任何其他方法可以帮助您干扰浏览器的打印.

Of course if you just want to print 2 copies, this may be way too over killed and too complicated to implement. But I'm not aware of any other way that can help you interfere with the browser's printing.

这篇关于Window.print()将默认副本设置为2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆