Solved

Java applet accessing printer?

Posted on 1998-10-25
6
696 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Accepted Solution

by:
Brill earned 50 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

632 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