-1

I want to generate POS (Point Of Sale) receipt from web browser using Java.

How can I print pos receipt?

I believe jzebra may be an option, but how?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

Note: I really doubt that you will find a browser "willing" to send directly anything to the printer without user approval - it will be a great way to attack unsuspecting users landing on a malicious website. So, sorry, no - there's nothing you can do client-side (Java or any other language).

So either format your receipt as HTML (perilous job, each broswer with it's own font settings) or make your server generate a downloadable PDF which the user can afterwards print.

For the PDF generation on the server-side running on Java:

  • install a PDF "print-to-file" virtual printer (on Linux, I used a CUPS-PDF configuration with the results directed in a temp directory);

  • make your "POS receipt renderer" class adopt the Printable interface and implement the rendering of your POS receipt

  • organize the code of your 'POS generator' to open/configure a PrinterJob configured to use your receipt renderer and against the PrintService identifying you PDF-virtual-printer. Tutorial on Java Printing

  • once the job finishes printing, take it from the destination directory and deliver it as a download the user browser with a mime-type of application/pdf

Everything above it will require 3-4 classes, so sorry for not showing you some code (it will be somehow dependent on the server-side logic and the chosen PDF virtual printer, especially in the "detect that the PDF printing is complete" part).

Adrian Colomitchi
  • 3,974
  • 1
  • 14
  • 23
0

Printing materials over web browser was possible with Java Applet and similar technologies (based on NPAPI). But the support for NPAPI is nearly extinct in most major web broswers.

For further information on how to proceed after NPAPI support is dropped, please refer to this question.

Alternative to Jzebra/QZ Java Raw Print Plugin after NPAPI being dropped on Chrome Browser

Community
  • 1
  • 1
JuniorDev
  • 1,170
  • 2
  • 9
  • 19