This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Printing from an applet  RSS feed

 
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
 
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.
 
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.
 
Bartender
Posts: 9550
12
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
Boost this thread!