Java 如何从 Web 应用程序打印到收据打印机?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2192502/
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-13 04:35:43  来源:igfitidea点击:

How to print from web application to receipt printer?

javagrailsjasper-reportspoint-of-sale

提问by nightingale2k1

I was asked by my client to print receipts on an Epson TM U220 (http://pos.epson.com/products/TM-U220.htm) from my web application. I have no idea how to do that. Are there any java applets or something else that I can use for printing? Should i use JasperReports? (Does JasperReports help to cope with this problem?) If there are flash apps that could be used, I have no objection to using that.

我的客户要求我从我的 Web 应用程序在 Epson TM U220 ( http://pos.epson.com/products/TM-U220.htm)上打印收据。我不知道该怎么做。是否有任何 Java 小程序或其他可用于打印的东西?我应该使用 JasperReports 吗?(JasperReports 对解决这个问题有帮助吗?)如果有可以使用的flash 应用程序,我不反对使用它。

I am using Grails for my web apps.

我正在将 Grails 用于我的网络应用程序。

回答by Cesar

You don't need an applet, from a grails controller you may use any Java library. Use the Java printing services available to the runtime in javax.print. This is assuming that the printer is installed where the grails runtime is running.

您不需要小程序,您可以从 grails 控制器使用任何 Java 库。使用 javax.print 中运行时可用的 Java 打印服务。这是假设打印机安装在运行 grails 运行时的地方。

回答by SOA Nerd

I created an app to write to a receipt printer for a POS system a while back. The way we did it was to just open a printwriter that pipes to the correct receipt printer. We manually sent the character codes to the printer to create bold, underline, font changes, etc because of requirements from the client that we do it that way (there was another application that used these character codes and they wanted us to use them also).

不久前,我创建了一个应用程序来写入 POS 系统的收据打印机。我们这样做的方法是打开一个打印器,通过管道连接到正确的收据打印机。我们手动将字符代码发送到打印机以创建粗体、下划线、字体更改等,因为客户要求我们这样做(有另一个应用程序使用这些字符代码,他们也希望我们也使用它们) .

If you don't want to go through the manual process like I did a good choice is JavaPOS. It has got alot of stuff related to printing to receipt printers (definately much more elegant than I described above). You'll find it at http://www.javapos.com/.

如果您不想像我一样经历手动过程,那么 JavaPOS 是一个不错的选择。它有很多与打印到收据打印机相关的东西(肯定比我上面描述的要优雅得多)。您可以在http://www.javapos.com/ 上找到它。

回答by Jeremy Thompson

To get this working, simply setup your receipt printer as the default printer and rename it as "zebra":

要使其正常工作,只需将收据打印机设置为默认打印机并将其重命名为“斑马”:

enter image description here

在此处输入图片说明

Then simply download the jZebralibrary, put the jar file in the project directory and hey presto:

然后只需下载jZebra库,将 jar 文件放在项目目录中,嘿嘿:

<input type=button onClick="print()" value="Print">
<applet name="jzebra" code="jzebra.PrintApplet.class" archive="./jzebra.jar" width="100" height="100">
      <param name="printer" value="zebra">
</applet>

<script>
      function print() {
       document.jzebra.append("PRINTED USING JZEBRA\n");
       document.jzebra.print();
      }
</script>

enter image description here

在此处输入图片说明