Printing from a JDK1.1 applet without the java plug-in

Posted on 2000-01-13
Medium Priority
Last Modified: 2013-12-29
I am programming an applet with JDK1.1 that should be able to print the images it contains. I found out that even if I sign my applet and configure the client to trust it, no browser would allow my applet to overcome the sandbox restrictions unless my client downloads the Java 2 runtime enviroment including the java plug-in software. I don't want my clients to download huge amounts of data in order to be able to use the printing functionality of my applet. Is there a way to print from an applet in JDK1.x ? or a way to work around the security restrictions without signing applets which obviously doesn't work in the Java 1 enviroment? Any suggestions?  
Question by:jida
  • 3
  • 2

Author Comment

ID: 2348634
Edited text of question.

Author Comment

ID: 2348676
Adjusted points to 200

Expert Comment

ID: 2349182
which browsers u use?
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.


Accepted Solution

vladi21 earned 800 total points
ID: 2349193
good article with example

1) Your must sign applet in browser specific way

Code Signing for Java Applets
java how-to http://tactika.com/realhome/javaht/java-s1.html

Unfortunately the Java Development Kit (JDK TM) 1.1 signing and verification is not supported by the web browsers (NetscapeTM's and Microsoft's.) It is supported in HotJavaTM, http://java.sun.com/products/hotjava and appletviewer.

You can use the JavaTM Plug-in in the browsers to get access to more recent JDK technology, http://java.sun.com/products/plugin. You can run 1.1.x signed applets with the Plug-in plugged into the browsers.

without plugin:
Java Signing FAQ  http://www.fastlane.net/~tlandry/javafaq.txt

Developer FAQ for Java Code Signing in Microsoft Internet Explorer 4.01 and Later

Software Developer Digital IDsSM for Netscape Object Signing:
JAVA CAPABILITIES API http://developer.netscape.com/docs/manuals/signedobj/capsapi.html
OBJECT SIGNING FAQ  http://developer.netscape.com/support/faqs/objfaq.html
DevEdge Newsgroup FAQ: Security http://developer.netscape.com/support/faqs/champions/security.html

NN: Bypass the need for a certificate
COMMUNICATOR 4.5 PREFERENCES  http://developer.netscape.com/docs/manuals/deploymt/4_5PREFS.HTM
Netscape provides a way to accept a codebase as trusted (then a certificate is not needed). This can be useful during development or in a private Intranet. In the Netscape Users directory, there is a file called prefs.js. Adding the line user_pref("signed.applets.codebase_principal_support", true);
will enable JAR file without a certificate to request privileges on your machine. If you agree, it will be possible for an Applet to lauch a program, write a file on your hard disk or print on the printer. You will still have to ask for privileges in your program using the Netscape capabilites classes.
Another way is to lower general security setting to more allow more freedom when running applets locally. Add or modify the following entries in the prefs.js: user_pref("unsigned.applets.low_security_for_local_classes", true);
user_pref("signed.applets.local_classes_have_30_powers", true);
user_pref("signed.applets.low_security_for_local_classes", true);
user_pref("signed.applets.verbose_security_exception", true);

Then you don't need to asked for privileges for local classes.
When adding or modifying the file prefs.js, Netscape must not be running because your modification will be overwritten. So shut down Netscape, edit the prefs.js and then restart Netscape.

2) Print
Java 1.1
Using Design Patterns to Simplify Printing in Java 1.1 *
How do I print out a component in Java 1.1?

Java 1.2
How can I speed up printing in my JDK 1.2 Swing application?

bugs in Java2 printing API

  2. (Sect. 8) How do I print from a Java program?

     [*] Use the Toolkit.getPrintJob() method

     Component c = this.getParent();
     while (c!=null && !(c instanceof Frame))

     PrintJob pj = getToolkit().getPrintJob((Frame) c, "test", null);
     Graphics pg = pj.getGraphics();

     This feature was introduced with JDK 1.1. A common place to put this is
     in the code that handles a button press. Printing from an untrusted
     applet is subject to a check from the SecurityManager.

     The JDK 1.1 printing API is more a screen hardcopy facility than a full
     blown publishing and illustration hardcopy API. JDK 1.2 offers a more
     full-featured printing API.

     If you simply want to print text, then write it to a file and print the
     file. Or open a filename that corresponds to the printer. On Windows,
     that is "LPT1" and the code looks like:

     try {
         FileOutputStream fos = new FileOutputStream("LPT1");
         PrintStream ps = new PrintStream(fos);
                 ps.print("Your string goes here");
     } catch (Exception e) {
         System.out.println("Exception occurred: " + e);

     The final formfeed is needed by windows to start the printjob.

  3. (Sect. 8) What are the properties that can be used in a PrintJob? The
     properties are
        o awt.print.destination - can be "printer" or "file"
        o awt.print.printer - printer name
        o awt.print.fileName - name of the file to print
        o awt.print.numCopies - obvious
        o awt.print.options - options to pass to the print command
        o awt.print.orientation - can be "portrait" or "landscape"
        o awt.print.paperSize - can be "letter","legal","executive" or "a4"
     The defaults are destination=printer, orientation=portrait,
     paperSize=letter, and numCopies=1.

     You can search for info like this by joining the Java Developer
     Connection (it's free) at http://java.sun.com/jdc.

     and doing a search for "PrintJob".

Without going into too much detail, Netscape Communicator enables signed applets to request permission to access various system resources. It is left up to the user to grant or deny access.

An applet requests access to a system's printing resources by enabling the UniversalPrintJobAccess privilege. Once the privilege has been granted, the applet can proceed exactly as outlined above. To enable the print job privilege, you use the following code:

import netscape.security.PrivilegeManager;
import netscape.security.ForbiddenTargetException;
try {

PrivilegeManager.enablePrivilege ("UniversalPrintJobAccess");
// proceed with printing as normal
PrivilegeManager.disablePrivilege ("UniversalPrintJobAccess");

} catch (ForbiddenTargetException e) {

// user denied applet permission to access resource


The JavaT Printing Project
a simple, easy to use, Pure JavaT, Open-Source printing package built on the current Java2 Platform printing API's.
Ability to print anything from plain text to complex documents.
PDF and PostScript output to files.
Print Preview with zoom in/zoom out ability.
Continuous updates through future Java PlatformT releases (i.e. Java3).

Expert Comment

ID: 2355839
You could move your printing code to an application and modify
your print content to downloadable links that invoke the app.
The overhead ofcourse would be downloading your printing app and registering the MIME type in your client browsers. Do correct me if this system cannot be implemented, just a thought.

Author Comment

ID: 2378732
To arcifus: Thank you for your suggestion. In my case, I don't want my clinet to do any work on his side (such as registering the MIME type in his/her browser). To be quite honest, I did not investigate your suggestion any further, since I found vladi21's suggestion to sign my applet using the browser specific tools to be much more straight forward and easy to implement. It also does not involve much work on the client side. Thanks anyway :-)

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month4 days, 3 hours left to enroll

599 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