使用Java将EPL打印到Zebra

时间:2019-04-11 01:03:40

标签: java zebra-printers epl

我正在尝试将数据打印到Zebra TLP2844。 我使用OsX CUPS进行了配置。我选择Zebra,然后选择EPL2驱动程序。这是我可以获得打印测试页的唯一方法。

然后,当我尝试从Java打印一系列EPL命令时,将打印命令而不是所需的结果。 正如我期望使用某些图形界面一样,我正在使用处理对其进行编码。 这是我正在使用的代码:

// Let's assume I'm working with some shape models that are defined in some
// external library that's out of my control.
sealed trait Shape
case class Circle() extends Shape
case class Triangle() extends Shape

// Now I'm building an add that adds stuff to a Document
// and I want to locally implement methods that work on these general shapes.
case class Document()

// Using implicit conversion to add methods to a case class that's just holding data
implicit class DocumentExtensions(doc: Document) {
  // I don't want this to be called
  def add(shape: Shape): Unit = println("Add a shape")

  // I want to use shape-specific methods
  def add(shape: Circle): Unit = println("Add a circle")
  def add(shape: Triangle): Unit = println("Add a triangle")
}

val doc = Document()
val shapes = Seq(Circle(), Triangle())

// This just prints "Add a shape" for the Circle and Triangle.
// I want to it to print "Add a circle" and "Add a triangle".
shapes.foreach { shape =>
  // QUESTION:
  // Is there a way or pattern to have this call the add for the
  // subclass instead of for Shape? I want this to be fully dynamic
  // so that I don't have to list out each subclass. Even more ideally,
  // the compiler could warn me if there was a subclass that there wasn't
  // an implicit add for.
  doc.add(shape)
}

// This would work, but I'm wondering if there's a way to do this more
// dynamically without listing everything out.
shapes.foreach {
  case c: Circle => doc.add(c)
  case t: Triangle => doc.add(t)
}

我应该使用原始命令来做其他打印吗? 我还在CUPS上将打印机配置为原始打印机,但这没用。

0 个答案:

没有答案