4

Well I have created a web-based POS to take order. My question is how do I create a Java-Applet;

  1. Shows the HTML page & a Print button
  2. Print Order without prompting(no dialogue box)

Additional Information : It works like this. The waiter will key the orders from the computer(POS) , when they hit print, it will detect the I.P address of the printer in the kitchen,then print out the orders immediately without prompt. I am actually looking for reference/guide which can help me start on. Any Advise will be helpful as well. Thank you

Boon Ping
  • 43
  • 1
  • 5

2 Answers2

4

You cannot do that for security reasons. If you could, applets would already have become notorious for printing 10+ pages of 'special offers' when you visit unscrupulous web sites.

OTOH, if the client is willing to accept one prompt at applet start-up, you could digitally sign the code.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • That digital signature approach sounds pretty awesome. I hadn't realized that it would be so easy to step outside the Java security sandbox. – sarnold Dec 19 '11 at 03:16
  • @sarnold I prefer to use the services of the JNLP API where possible. Those applets (and applications) come to screen unprompted, but if the user/app. invokes a print, a dialog asking for 'print permissions' pops to screen. Like [this demo. of the `PrintService`](http://pscode.org/jws/api.html#prs). It is a lot less scary than accepting a signed applet that can then do 'anything', like [this properties applet](http://pscode.org/prop/all.html?prop=java.home). (Both apps. from my site, neither intended to cause havoc.) – Andrew Thompson Dec 19 '11 at 03:40
  • Jeeze, I have to wait another 24 hours before I can award the bounty. Go figure. That's an amazing assortment of code you've constructed, an amazing resource. :) – sarnold Dec 19 '11 at 21:44
  • @sarnold Thanks for the bounty! I just wish the OP had taken the advice to edit this question with info. like that the clients were connected by LAN etc., mentioned in comments on questions now closed. This might have become a more interesting question still. – Andrew Thompson Dec 21 '11 at 00:29
  • 1
    It still could become more interesting -- Boon Ping, care to make the edits suggested elsewhere? :) – sarnold Dec 21 '11 at 00:46
  • @AndrewThompson I have the same requirement as OP now. The links you have provided in the comment seems to be down. Can you please help? – Keerthivasan May 24 '14 at 05:18
  • @Octopus Unfortunately the site is down. Fortunately you can still get the [build files for the demos](https://drive.google.com/?tab=mo&authuser=0#folders/0B5B9wDXIGw9lUWN4OTgyNTVkbEU) on my share drive. The properties applet was neither here nor there, and is now not available anywhere. – Andrew Thompson May 24 '14 at 05:25
0

There is a project that does HTML printing using HTML5 to render the contents to a PNG and Java to print directly, exactly as described in the original post. This project is called "qz-print" (previously called "jzebra") and it offers the digital signature in both self-signed (free) and trusted-signed (at a premium).

It also uses the signed JNLP files as Andrew Thompson has illustrated. (Thanks Andrew, your contributions to Java as a whole have been a great help to Java developers around the world).

https://code.google.com/p/jzebra/