• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing from an applet

 
Me
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to print from an applet?
I can print using java print api from an application but service lookup fails in an applet?

As a matter of fact
PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
returns null.



If it is possible can anybody give me a sample of working code?

Regards
 
tommy k. lee
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java specifies that it is a security violation to print from a regular (untrusted) applet, just as it is a security violation to read or write files on the user's machine. As a result, Java will automatically prompt the user with "An applet would like to print. Is this OK?", so the user can say "yes" or "no". In order to print from an applet without this prompt, you need to "sign" your applet or set up the security policy on the user's machine to grant your applet the printing privilege.
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is difficult to print from an applet and should be avoided whenever possible, if there is any other way to do what you are trying to do, i sugest you do it that way, instead of printing through the applet.
 
Me
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tommy k. lee:
"An applet would like to print. Is this OK?" ...


Even if, I get this message for printing from unsigned applets that will be fine. But I could never get even this message.
 
Joe Ess
Bartender
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the documentation for javax.print.PrintServiceLookup, an applet must be signed before it can print:

A PrintServiceLookup implementor is recommended to check for the SecurityManager.checkPrintJobAccess() to deny access to untrusted code. Following this recommended policy means that untrusted code may not be able to locate any print services. Downloaded applets are the most common example of untrusted code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic