Solved

Java applet accessing printer?

Posted on 1998-10-25
6
686 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Accepted Solution

by:
Brill earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nestparen challenge 4 55
topping1 challenge 7 48
java set up 1 45
Responding to Java JComponent extended classes's resize event 4 22
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now