Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java applet accessing printer?

Posted on 1998-10-25
6
Medium Priority
?
697 Views
Last Modified: 2013-12-22
Hi,

Is it possible for a Java applet to access a default local print of my web browser?

I am trying to write a Java applet directly print some report(may be text + graphics) to the default printer of my web browser.

Is it possible to do it now with JDK1.1.X?
0
Comment
Question by:koala1998
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:Mukund
ID: 1226341
Yes. You can use the new printer object in JDK 1.1 to display all of your screen output in the printer.  You basically use the printer object instead of the graphics object in your paint module. You need to remember to flush each page (no default form feed).  
0
 

Author Comment

by:koala1998
ID: 1226342
Okay, but may be I did not specify very clearly in my question.  What I wanted is, to provide the user with a list windows, in which listed are all the printable document from my server.  

What I wanted to do is after the user has selected a certain document, he can press a "print" button, and that docuemnt will be automatically loaded from the server and be printed to a default printer.

Can Java achieve that?
0
 
LVL 1

Expert Comment

by:gerry99
ID: 1226343
Sure, you could write an applet to display the list of
printable documents, and I response to the user's button press
you could print the appropriate file to his printer using the
aforementioned printer object.

You will need to sign your applet in order to obtain the security
permissions needed to print to the user's printer.  Both Netscape
and Microsoft do it differently, so you will need to bits of code and 2 digital IDs.  In addition, since the Netscape capability API is not present in the IE Java implementation, you will need to do browser detection and only load the appropriate
printing code for each browser.  It's possible and I've done it, although I was printing the contents of a graphically rendered AWT Frame, not a text document.

Depending on your time budget you may want to just display the server documents in a new browser window, and let the browser print them, when the user presses the print button.
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Accepted Solution

by:
Brill earned 150 total points
ID: 1226344
Yes. However, you will have to sign the applet. Both Netscape & IE require a different certificate. Both the Microsoft and Netscape sites have extensive information on how this is done. If you are signing for another browser, you'll have to find out first if the browser supports signed applets, and how the certificate can be applied.
0
 

Author Comment

by:koala1998
ID: 1226345
Thanks for your response.  But one more question is where can I obtain those two Digital ID?  And what is that "bits of code"?
0
 

Expert Comment

by:Brill
ID: 1226346
There doesn't seem to be a way to edit or delete an answer I have already submitted, but I thought I'd expand on what I'd already entered. So, this is the answer that should be up top

Yes. However, you will have to sign the applet in order to give the applet access outside the browsers sandbox. Both Netscape & IE require a different certificate. Both the Microsoft and Netscape sites have extensive information on how this is done. If you are signing for another browser, you'll have to find out first if the browser supports signed applets, and how the certificate can be applied.

The two methods I have used/seen to allow an applet to run in both Netscape & IE, is to implement a 'do-nothing' security class, or catch ClassNotFound exceptions. In the 'do-nothing' case the Browser will load its own version of the class before it tries to load the 'do-nothing' version. What that means, is that in all situations, the applet is requesting access for both browsers... the one that matters will be the one granting the access. You can also catch ClassNotFound exceptions. This is not the prefereed way to do it however, becase the Web server the applet comes from will get a 404 (File Not Found) error logged to its log. (this happens becase the VM will try to find the class file on the server if its not in the system, or the jar archive).
An example of both the Netscape and IE 'do-nothing' classes follows:

The MS do-nothing classes (there are two required)
-------------------------------------
ackage com.ms.security;
lass PermissionID


-------------------------------------
ackage com.ms.security;
ublic class PolicyEngine

public static void assertPermission( PermissionID p){
      // do nothing!!!  This class will be loaded from Microsoft's system class
      // if and only if we are running in the Explorer VM!!!
      return;
}

public static synchronized PermissionID permissionNameToID(String pname){
      return null;!
}

-------------------------------------
And the Netscape class.
-------------------------------------
ackage netscape.security;
public class PrivilegeManager

public static void enablePrivilege( String priv){
      // do nothing!!!  This class will be loaded from Netscape's system class
      // if and only if we are running in the Netscape VM!!!
      return;
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question