1. 程式人生 > >android網頁打印,安卓網頁打印,h5頁面打印,瀏覽器打印,js打印工具

android網頁打印,安卓網頁打印,h5頁面打印,瀏覽器打印,js打印工具

rgb size with auto html 開發者 測試 二維碼 height

Android設備打印比較麻煩,一般設備廠商都提供原生app開發的SDK,我們web開發者為難了,不會原生開發啊

給大家提供一個思路,實現web加殼,利用打印瀏覽器實現

簡單來說就是把我們的web頁面嵌入瀏覽器中

web頁面的打印功能通過js與瀏覽器互動

瀏覽器通過調用硬件SDK實現打印

1、機器安裝最新SDK,已安裝請忽略

2、下載安裝本頁下載連接中的打印瀏覽器並安裝

3、對照下方事例代碼,修改web頁面打印功能

4、打印瀏覽器中打開web頁面,測試打印功能

5、默認主頁可以在SD卡根目錄修改homepage.txt中的網址

*以上所有步驟必須在智谷聯產品上使用,詳情咨詢銷售工程師

軟件支持android網頁打印工具,安卓網頁打印工具,h5頁面打印,瀏覽器打印,js打印工具

web頁面按照如下事例,修改打印函數代碼,調用打印API即可完成打印功能

<html>
<head>
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
    <script type=‘text/javascript‘ src=‘//g.alicdn.com/sj/lib/zepto/zepto.min.js‘ charset=‘utf-8‘></script>
    <script type=‘text/javascript‘ src=‘//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js‘ charset=‘utf-8‘></script>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
        div {
            margin: 5px 0;
        }

        input {
            width: 49%;
            height: 45 px;
            margin-right: 1%;
            margin-bottom: 1%;
        }

        #tipinfo {
            font-size: 15px;
            color: rgb(255,0,0);
            font-style: italic;
            height: auto;
        }
    </style>
    <script type="text/javascript">

        function javacalljs() {
            document.getElementById("tipinfo").innerHTML =
                "<br\>JAVA調用了JS的無參函數";
        }

        function javacalljswith(arg) {
            document.getElementById("tipinfo").innerHTML = (arg);
        }
    </script>
</head>
<body>
    <header class="bar bar-nav">
        <h1 class=‘title‘>網頁打印演示</h1>
    </header>
    <div class="content">
        <div class="content-padded grid-demo">

            <div id="tipinfo">打印機狀態</div>
            <div class="item-content">
                <div class="item-media"><i class="icon icon-form-comment"></i></div>
                <div class="item-inner">
                    <div class="item-title label">輸入打印內容</div>
                    <div class="item-input">
                        <textarea id="inputtxt">打印內容測試,一維碼生成請輸入數字</textarea>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="生成二維碼" onclick="window.android.createQRCode(document.getElementById(‘inputtxt‘).value)" />
                </div>
                <div class="col-50">
                    <input type="button" class="button button-fill" value="生成條碼" onclick="window.android.createBarCode(document.getElementById(‘inputtxt‘).value)" />
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印文本" onclick="window.android.printText(document.getElementById(‘inputtxt‘).value)" />
                </div>
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印Unicode" onclick="window.android.printUnicode(‘hello, begin to smart print!‘)" />
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="選擇圖片" onclick="window.android.selectPic()" />
                </div>
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印圖片" onclick="window.android.printPic()" />
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印網絡圖片" onclick="window.android.printNetPic()" />
                </div>
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印模板二" onclick="window.android.printStyleTwo()" />
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印模板一" onclick="window.android.printStyleOne()" />
                </div>
                <div class="col-50">
                    <input type="button" class="button button-fill" value="打印模板三" onclick="window.android.printStyleThree()" />
                </div>
            </div>
            <div class="row">
                <div class="col-50">
                    <input type="button" class="button button-fill" value="獲取打印機狀態" onclick="window.android.getPrintStatus()" />
                </div>
            </div>
        </div>
    </div>
</body>
</html>

android網頁打印,安卓網頁打印,h5頁面打印,瀏覽器打印,js打印工具