js 通过控件打印

打印方法

function PrintPage() {
            try {
                if (testPrintContorl()) {
                    hideNoPrintElement();
                    factory.printing.Print(false); //设置为false,直接打印
                    showNoPrintElement();
                } else {
                    return false;
                }
            } catch (e) {
                alert("打印出错,请确定使用的是IE浏览器!\n请确定已经安装打印机并正确的链接到打印机!");
                showNoPrintElement();
            }
        }
       
    function SetPrintSettings() {
        if(testPrintContorl()) {
            factory.printing.header = "";
            factory.printing.footer = "";
            factory.printing.portrait = true; //方向,true
            factory.printing.leftMargin = 0.3; //mm
            factory.printing.topMargin = 0.3;
            factory.printing.rightMargin = 0.3;
            factory.printing.bottomMargin = 0.3;
        } else {
            return false;
        }
    }
    function CallPrintSetUp() {
        if (testPrintContorl()) {
            factory.printing.PageSetup();
        } else {
            return false;
        }
    }
    function CallPrintPrivew() {
        if(testPrintContorl()) {
            factory.printing.Preview();
        } else {
            return false;
        }
    }
  
    function moveBackClick() {
        var rootPage = parent.parent;
        if(rootPage == null) {
            history.back();
        } else {
            try {
                rootPage.GB_hide();
            } catch(ex) {
                history.back();
            }
        }
    }
    function testPrintContorl() {
        if (!factory.object) {
            if (confirm("页面打印控件还没有安装!\n请点击确定转到安装页面")) {
                window.open("../PrintControl/PrintControlSetUpInfo.htm", "_self");
                //window.open("../PrintControl/smsx.exe","width=100,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100");
            }
            return false;
        } else {
            return true;
        }
    }
    function hideNoPrintElement() {
        var nph = document.getElementById("NoPrint");
        if (null != nph) {
            nph.style.display = "none";
        }
    }
    function showNoPrintElement() {
        var nph = document.getElementById("NoPrint");
        if (null != nph) {
            nph.style.display = "";
        }
    }

    function initPage() {
        if (testPrintContorl()) {
            SetPrintSettings();
        } else {
            return false;
        }
    }

    window.onload = initPage;

使用的控件

<object id="factory" style="display:none" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="../PrintControl/smsx.cab#Version=6,3,435,20">
    <param name="template" value="MeadCo://IE7" />
</object>

转载于:https://www.cnblogs.com/feidaochuanqing/archive/2013/03/09/2951213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值