打印机上打印的Andr​​oid文 [英] Android print text on printer

查看:171
本文介绍了打印机上打印的Andr​​oid文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个餐厅的应用程序后,该客户购买的食物的打印收据。我已经添加在应用的配置屏幕,该管理器用于配置打印机。经理可以打印测试页来测试他是否已经进入正确的IP和端口。这里是我的code它打印测试页:

I am developing a restaurant app which print receipts after customer purchases foods. I have added a config screen in app which the manager uses to configure printers. A manager can print a test page to test whether he has entered right ip and port. Here is my code which prints test page:

private class PrintTask extends AsyncTask<Printer, Boolean, String> {

    @Override
    protected String doInBackground(Printer... params) {

        try {
            publishProgress(true);
            Socket sock = new Socket(params[0].getIp(), Integer.parseInt(params[0].getPort()));

            PrintWriter oStream = new PrintWriter(sock.getOutputStream());
            oStream.printf("--------------------------------\r\n");
            oStream.printf("***        TEST PRINT       ***\r\n");
            oStream.printf("You have configured your \n\r");
            oStream.printf(params[0].getName());
            oStream.printf("\r\nprinter successfully\n\r");
            oStream.printf("|           Thanks             |\r\n");
            oStream.printf("--------------------------------\r\n");
            oStream.close();
            sock.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        publishProgress(false);
        return "";
    }

    @Override
    protected void onProgressUpdate(Boolean... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
        if(!values[0]) {
            waitView.setVisibility(View.GONE);
        }
        else {
            waitView.setVisibility(View.VISIBLE);
        }
    }

}

问题是如果我的网络打印机(不附加任何一台PC一个独立的打印机)上打印文本打印正确。在这里,我使用的IP地址和默认端口9100。但是,当我打印到连接到PC的共享打印机,它无法打印。任何想法,我哪里做错了... ???

The problem is if I print on a network printer (a stand alone printer without attaching to any PC) it prints text properly. Here I am using the ip and default port 9100. But when I print to a shared printer attached to a PC, it fails to print. Any idea, where I am doing wrong...???

推荐答案

从你的描述它看起来像独立的打印机正在运行的指定端口上的某种文本打印服务。所以看起来你发送到这个端口将被打印为文本的一切。

From what your describe it looks like that standalone printer is running some kind of "text printing service" on your given port. So looks like everything you send to this port will be printed as text.

而当你有你的Windows机器上共享打印机,它使用Windows打印机服务或水木清华这样的实现。这不只是简单的socket /端口了,你可以写ASCII文本。

Whereas when you have "Shared" printer on your Windows machine, it's implemented using Windows Printer service or smth like that. It's not just simple socket/port anymore where you can write ASCII text.

这篇关于打印机上打印的Andr​​oid文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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