使用 POS 打印机打印 Javascript 收据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11463787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 05:55:59  来源:igfitidea点击:

Javascript receipt printing using POS Printer

javascriptjqueryprinting

提问by Sachindra

In a web application I want to print a receipt using a POS (Point of Sale) Printer. I want to do that with Javascript. Can anyone provide me an example for that?

在 Web 应用程序中,我想使用 POS(销售点)打印机打印收据。我想用 Javascript 做到这一点。任何人都可以为我提供一个例子吗?

采纳答案by Scott Selby

I'm going out on a limb here , since your question was not very detailed, that a) your receipt printer is a thermal printer that needs raw data, b) that "from javascript" you are talking about printing from the web browser and c) that you do not have access to send raw data from browser

由于您的问题不是很详细,因此我要在这里讨论一下,a)您的收据打印机是需要原始数据的热敏打印机,b)您正在谈论从网络浏览器打印的“来自javascript”和c) 您无权从浏览器发送原始数据

Here is a Java Applet that solves all that for you , if I'm correct about those assumptions then you need either Java, Flash, or Silverlight http://code.google.com/p/jzebra/

这是一个 Java Applet,可以为您解决所有问题,如果我对这些假设是正确的,那么您需要 Java、Flash 或 Silverlight http://code.google.com/p/jzebra/

回答by Craig

If you are talking about a browser based POS app then it basically can't be done out of the box. There are a number of alternatives.

如果您谈论的是基于浏览器的 POS 应用程序,那么它基本上无法开箱即用。有多种选择。

  1. Use an applet like Scott Selby says
  2. Print from the server. If this is a cloud server, ie not connectable to the receipt printer then what you can do is
    • From the server generate it as a pdf which can be made to popup a print dialog in the browser
    • Use something like Google Cloud Print which will allow connecting printers to a cloud service
  1. 使用像 Scott Selby 所说的小程序
  2. 从服务器打印。如果这是云服务器,即无法连接到收据打印机,那么您可以做的是
    • 从服务器将其生成为 pdf 格式,可以在浏览器中弹出打印对话框
    • 使用 Google Cloud Print 之类的东西,它允许将打印机连接到云服务

回答by Richard Cotrina

EDIT: NOV 27th, 2017 ─ BROKEN LINKS

编辑:2017 年 11 月 27 日 ─ 链接断开

Links below about the posts written by David Kelleyare broken.

以下有关David Kelley所写帖子的链接已损坏

There are cached versions of the repository, just add cache:before the URL in the Chrome Browser and hit enter.

有存储库的缓存版本,只需cache:在 Chrome 浏览器中的 URL 之前添加并按 Enter。



This solution is only for Google Chromeand Chromium-basedbrowsers.

此解决方案仅适用于Google Chrome基于 Chromium 的浏览器。

EDIT:

编辑:

(*)The links are broken. Fortunately I found this repositorythat contains the source of the post in the following markdown files: A| B

(*)链接已损坏。幸运的是,我在以下 markdown 文件中找到了包含帖子来源的存储库A|

This link* explains how to make a Javascript Interface for ESC/POS printers using Chrome/Chromium USB API(1)(2). This link* explains how to Connect to USB devices using the chrome.usb.*API.

这个链接* 解释了如何使用 Chrome/Chromium USB API (1) (2)为 ESC/POS 打印机制作 Javascript 接口。 这个链接* 解释了如何使用chrome.usb.*API连接到 USB 设备。

回答by Habib Sheikh

I have recently implemented the receipt printing simply by pressing a button on a web page, without having to enter the printer options. I have done it using EPSON javascript SDK for ePOS. I have test it on EPSON TM-m30receipt printer.

我最近通过按网页上的按钮实现了收据打印,而无需输入打印机选项。我已经使用EPSON javascript SDK for ePOS完成了它。我已经在EPSON TM-m30收据打印机上进行了测试。

Here is the sample code.

这是示例代码。

var printer = null;
var ePosDev = null;

function InitMyPrinter() {
    console.log("Init Printer");

    var printerPort = 8008;
    var printerAddress = "192.168.198.168";
    if (isSSL) {
        printerPort = 8043;
    }
    ePosDev = new epson.ePOSDevice();
    ePosDev.connect(printerAddress, printerPort, cbConnect);
}

//Printing
function cbConnect(data) {
    if (data == 'OK' || data == 'SSL_CONNECT_OK') {
        ePosDev.createDevice('local_printer', ePosDev.DEVICE_TYPE_PRINTER,
            {'crypto': false, 'buffer': false}, cbCreateDevice_printer);
    } else {
        console.log(data);
    }
}

function cbCreateDevice_printer(devobj, retcode) {
    if (retcode == 'OK') {
        printer = devobj;
        printer.timeout = 60000;
        printer.onreceive = function (res) { //alert(res.success);
            console.log("Printer Object Created");

        };
        printer.oncoveropen = function () { //alert('coveropen');
            console.log("Printer Cover Open");

        };
    } else {
        console.log(retcode);
        isRegPrintConnected = false;
    }
}

function print(salePrintObj) {
    debugger;
    if (isRegPrintConnected == false
        || printer == null) {
        return;
    }
    console.log("Printing Started");


    printer.addLayout(printer.LAYOUT_RECEIPT, 800, 0, 0, 0, 35, 0);
    printer.addTextAlign(printer.ALIGN_CENTER);
    printer.addTextSmooth(true);
    printer.addText('\n');
    printer.addText('\n');

    printer.addTextDouble(true, true);
    printer.addText(CompanyName + '\n');

    printer.addTextDouble(false, false);
    printer.addText(CompanyHeader + '\n');
    printer.addText('\n');

    printer.addTextAlign(printer.ALIGN_LEFT);
    printer.addText('DATE: ' + currentDate + '\t\t');

    printer.addTextAlign(printer.ALIGN_RIGHT);
    printer.addText('TIME: ' + currentTime + '\n');

    printer.addTextAlign(printer.ALIGN_LEFT);

    printer.addTextAlign(printer.ALIGN_RIGHT);
    printer.addText('REGISTER: ' + RegisterName + '\n');
    printer.addTextAlign(printer.ALIGN_LEFT);
    printer.addText('SALE # ' + SaleNumber + '\n');

    printer.addTextAlign(printer.ALIGN_CENTER);
    printer.addTextStyle(false, false, true, printer.COLOR_1);
    printer.addTextStyle(false, false, false, printer.COLOR_1);
    printer.addTextDouble(false, true);
    printer.addText('* SALE RECEIPT *\n');
    printer.addTextDouble(false, false);
....
....
....

}

回答by Karthik Sankar

I printed form javascript to a Star Micronics Webprnt TSP 654ii thermal printer. This printer is a wired network printer and you can draw the content to a HTML canvas and make a HTTP request to print. The only caveat is that, this printer does not support HTTPS protocol yet, so you will get a mixed content warning in production. Contacted Star micronics support and they said, they are working on HTTPS support and soon a firmware upgrade will be available. Also, looks like Epson Omnilink TM-88V printer with TM-I will support javascript printing.

我将表单 javascript 打印到 Star Micronics Webprnt TSP 654ii 热敏打印机。这台打印机是有线网络打印机,您可以将内容绘制到 HTML 画布上并发出 HTTP 请求进行打印。唯一需要注意的是,该打印机尚不支持 HTTPS 协议,因此您将在生产中收到混合内容警告。联系 Star micronics 支持,他们说,他们正在研究 HTTPS 支持,很快将提供固件升级。此外,看起来带有 TM-I 的 Epson Omnilink TM-88V 打印机将支持 javascript 打印。

Here is a sample code: https://github.com/w3cloud/starwebprint

这是一个示例代码:https: //github.com/w3cloud/starwebprint

回答by phyzalis

Maybe you could have a look at this if your printer is an epson. There is a javascript driver

如果您的打印机是爱普生,也许您可​​以看看这个。有一个 javascript 驱动程序

http://spsrprofessionals.com/ClientSite/readers/ePOS-Print_SDK_141020E/JavaScript/ePOS-Print_SDK_JS_en_revB.pdf

http://spsrprofessionals.com/ClientSite/readers/ePOS-Print_SDK_141020E/JavaScript/ePOS-Print_SDK_JS_en_revB.pdf

EDIT:

编辑:

Previous link seems to be broken

上一个链接好像坏了

All details about how to use epos of epson are on epson website:

有关如何使用 epson 的 epos 的所有详细信息都在 epson 网站上:

https://reference.epson-biz.com/modules/ref_epos_device_js_en/index.php?content_id=139

https://reference.epson-biz.com/modules/ref_epos_device_js_en/index.php?content_id=139

回答by Rajendra

try Escpos for PHP POS printing use https://github.com/mike42/escpos-php

尝试用于 PHP POS 打印的 Escpos 使用 https://github.com/mike42/escpos-php

回答by user1912424

You could try using https://www.printnode.comwhich is essentially exactly the service that you are looking for. You download and install a desktop client onto the users computer - https://www.printnode.com/download. You can then discover and print to any printers on that user's computer using their JSON API https://www.printnode.com/docs/api/curl/. They have lots of libs here: https://github.com/PrintNode/

您可以尝试使用https://www.printnode.com,这实际上正是您正在寻找的服务。您将桌面客户端下载并安装到用户计算机上 - https://www.printnode.com/download。然后,您可以使用他们的 JSON API https://www.printnode.com/docs/api/curl/发现并打印到该用户计算机上的任何打印机。他们在这里有很多库:https: //github.com/PrintNode/