溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用ScriptX控件進(jìn)行Web橫向打印

發(fā)布時(shí)間:2020-08-03 14:08:07 來源:網(wǎng)絡(luò) 閱讀:2022 作者:yuanzhitang 欄目:web開發(fā)

一個(gè)需求需要采用橫向打印,目前采用IE自身的打印功能(WebBrowser.ExecWB控件)很難進(jìn)行橫向設(shè)置,默認(rèn)需要調(diào)用document.all.WebBrowser.ExecWB(8,1);打開打印設(shè)置對(duì)話框進(jìn)行人工設(shè)置,頗為不方便,本次采用ActiveX控件,也即第三方的ScriptX控件進(jìn)行橫向設(shè)置。


ScriptX基本功能免費(fèi),但高級(jí)功能是收費(fèi)的,下面我就把最近在項(xiàng)目中使用ScriptX的經(jīng)驗(yàn)總結(jié)一下。


1. 首先把ScriptX.cab放在一個(gè)目錄下面,比如根目錄

2. 目前html5 doc需要把object放在head之外

引入如下


...

</head>

<object id="factory" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
        codebase="ScriptX.cab#Version=5,60,0,360"></object>

<body>

...


3. 設(shè)置打印屬性


function InitPrinterSetting() {
            factory.printing.header = "";//頁眉   
            factory.printing.footer = "";//頁腳    
            factory.printing.leftMargin = 1.0;//左邊距    
            factory.printing.topMargin = 1.3;//上邊距    
            factory.printing.rightMargin = 1.0;//右邊距    
            factory.printing.bottomMargin = 1.3;//下邊距   

            factory.printing.portrait = false;//打印方向,true:縱向.false:橫向    
        }


4.  如下style用于去除打印

 <style   media="print">      
      .Noprint{display:none;} <!--用本樣式在打印時(shí)隱藏非打印項(xiàng)目-->      
      .PageNext{page-break-after:   always;} <!--控制分頁-->      
    </style> 


完整代碼如下(附件可下載):


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PrintPreviewAndUnion.aspx.cs" Inherits="TMIS.WebApp.CustomerMA.PrintPreviewAndUnion" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
            <script type="text/javascript" src="../Scripts/lib/jquery-1.4.2.min.js"></script>
            <script type="text/javascript" src="../Scripts/lib/jquery-ui-1.8.5.custom.min.js"></script>
            <script type="text/javascript" src="../Scripts/lib/jquery.formatCurrency-1.4.0.min.js"></script>
            <script type="text/javascript" src="../Scripts/lib/jquery.utils.js"></script>
            <script type="text/javascript" src="../Scripts/lib/jquery.numeric.pack.js"></script>
            <script type="text/javascript" src="../Scripts/lib/jquery.timepickr.min.js"></script>
    <title>WebPrint</title>

    <script type="text/javascript">
 
        function PrintPage() {  
            factory.DoPrint(false);//設(shè)置為false,直接打印   
        }

        function InitPrinterSetting() {
            factory.printing.header = "";//頁眉   
            factory.printing.footer = "";//頁腳   
            factory.printing.leftMargin = 1.0;//左邊距   
            factory.printing.topMargin = 1.3;//上邊距   
            factory.printing.rightMargin = 1.0;//右邊距   
            factory.printing.bottomMargin = 1.3;//下邊距   

            factory.printing.portrait = false;//打印方向,true:縱向.false:橫向      
        }

    
        $(document).ready(function () {
            InitPrinterSetting();
        })

    </script>
 <style   media="print">      
      .Noprint{display:none;} <!--用本樣式在打印時(shí)隱藏非打印項(xiàng)目-->      
      .PageNext{page-break-after:   always;} <!--控制分頁-->      
    </style>  

</head>

  
    <object id="factory" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
        codebase="ScriptX.cab#Version=5,60,0,360"></object>

    <OBJECT   id="WebBrowser"   height="0"   width="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"   VIEWASTEXT></OBJECT>
<body>
    <form id="form1" runat="server">
    <div>
        <center>
          
           <div class="div_content" >
           
               <div style='text-align:center; padding-top:15px; padding-bottom:15px;' class='Noprint' >
                     <input  id="btnPrint" type="button"  value="直接打印"  />
                        &nbsp;&nbsp;&nbsp;&nbsp; 
                    <input  id='btnYes' value='打印預(yù)覽' type='button' onclick='document.all.WebBrowser.ExecWB(7,1);' style='width: 90px;height:31px;' />
                </div>
                <div id="print_div_receipt" >
                    <div >
                        <div >
                        <div ></div>
                            <span ><b>打印內(nèi)容</b></span>   
                        </div>
                     </div>                
                </div>
           
        </div>
        </center>
    </div>
    </form>
</body>
</html>


附件:http://down.51cto.com/data/2368505
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI