Solved

Java applet accessing printer?

Posted on 1998-10-25
6
693 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

839 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