首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ecs-pos热敏打印从浏览器

Ecs-pos热敏打印从浏览器
EN

Stack Overflow用户
提问于 2021-04-12 20:02:15
回答 0查看 280关注 0票数 0

我有一个角度项目,作为一个用户界面,能够打印票证的功能。我一直在试着让npm包正常工作。当我在浏览器中看到弹出窗口时,相应的github库(由bebo发布)会给我一个‘错误’,我看到了我的打印机。当我单击连接时,它会将有关打印机的一些信息记录到控制台。然后是app.component.ts“打印机未连接”的else语句中的代码。我已经在windows和linux机器上尝试过了。我还尝试为我的打印机安装特定于epson的驱动程序,并在windows中安装在ng-散热打印github存储库的一个开放问题中引用的驱动程序。我已经尝试了其他几个存储库,它们都不起作用,或者接近我正在尝试的东西(连接到usb打印机)。

因为我想让它尽可能简单,所以我只克隆了开发人员的github存储库:https://github.com/bebo925/ng-thermal-print#readme

我的代码和这个代码是一样的!按照要求,我会提供打字文件的代码...

说得非常清楚。我正在尝试让开发人员从github的代码工作。我的项目将很容易修复一旦开发人员的代码功能正常

开发人员代码:https://github.com/bebo925/ng-thermal-print#readme

来自github存储库的typescript代码:

代码语言:javascript
复制
import { PrintService, UsbDriver, WebPrintDriver } from "ng-thermal-print";
import { Component } from "@angular/core";
import { PrintDriver } from "ng-thermal-print/lib/drivers/PrintDriver";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {
  status: boolean = false;
  usbPrintDriver: UsbDriver;
  webPrintDriver: WebPrintDriver;
  ip: string = "10.83.118.160";

  constructor(private printService: PrintService) {
    this.usbPrintDriver = new UsbDriver();

    this.printService.isConnected.subscribe((result) => {
      this.status = result;
      if (result) {
        console.log("Connected to printer!!!");
      } else {
        console.log("Not connected to printer.");
      }
    });
  }

  requestUsb() {
    this.usbPrintDriver.requestUsb().subscribe(
      (result) => {
        this.printService.setDriver(this.usbPrintDriver);
      },
      (error) => {
        console.log(error);
      }
    );
  }

  connectToWebPrint() {
    this.webPrintDriver = new WebPrintDriver(this.ip);
    this.printService.setDriver(this.webPrintDriver, "WebPRNT");
  }

  print() {
    this.printService
      .init()
      .setBold(true)
      .writeLine("Hello World!")
      .setBold(false)
      .feed(4)
      .cut("full")
      .flush();
  }
}
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67058000

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档