[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

Printing from a Frame

I have an applet that uses a frame to capture some input and then applies some calculations and maniulates the input and I use another frame to to display the data and I want to print the data in that frame - I can't seem to make it work...
0
mapper
Asked:
mapper
  • 5
  • 4
  • 2
1 Solution
 
mapperAuthor Commented:
Edited text of question
0
 
gadioCommented:
mapper, in order to be able to print, your applet should be signed. Here is some reading material about signing an applet. If you need more info don't hesitate to ask.

Java signing FAQ: http://www.fastlane.net/~tlandry/javafaq.txt, that covers the latest versions of IE and Netscape, as well as the Java Activator.
Code signing: http://www.suitable.com/Doc_CodeSigning.shtml
 article about signing Applets for both IE and Netscape:
http://www.javareport.com/features/9801/sommers.html
Code signing for ActiveX is thoroughly detailed in
http://www.developer.com/reference/library/1575211610/ch23.htm
Security with ActiveX Authenticode appearing in http://www.gamelan.com
For Netscape Navigator, read about using the signing tool: http://developer.netscape.com/docs/manuals/signedobj/signtool/index.htm
programming with the Capabilities API: http://developer.netscape.com/docs/manuals/signedobj/capabilities/index.html
Object Signing Tool: http://developer.netscape.com/software/signedobj/jarpack.html
For Internet Explorer, the first article to read is:
http://www.microsoft.com/java/sdk/20/articles/trust_based_security.htm
And Signing a Cabinet File with java Permissions: http://www.microsoft.com/java/sdk/20/tools/signcode.htm
Also: http://www.microsoft.com/java/sdk/20/packages/security/default.htm
tools and documents are available for download in: http://www.microsoft.com/java/download.htm
Sun provides rudimentary tools for Signing and Verifying
JAR Files at:
http://www.javasoft.com/docs/books/tutorial/jar/sign/index.html (note that
they are not IE or NN compatible)

0
 
gadioCommented:
Sorry there is some extra links that you dont need. The liks you need are:

Java signing FAQ: http://www.fastlane.net/~tlandry/javafaq.txt, that covers the latest versions of IE and Netscape, as well as the Java Activator.
Code signing: http://www.suitable.com/Doc_CodeSigning.shtml
article about signing Applets for both IE and Netscape: http://www.javareport.com/features/9801/sommers.html
For Netscape Navigator, read about using the signing tool: http://developer.netscape.com/docs/manuals/signedobj/signtool/index.htm
programming with the Capabilities API: http://developer.netscape.com/docs/manuals/signedobj/capabilities/index.html
Object Signing Tool: http://developer.netscape.com/software/signedobj/jarpack.html
For Internet Explorer, the first article to read is: http://www.microsoft.com/java/sdk/20/articles/trust_based_security.htm
And Signing a Cabinet File with java Permissions: http://www.microsoft.com/java/sdk/20/tools/signcode.htm
Also: http://www.microsoft.com/java/sdk/20/packages/security/default.htm
tools and documents are available for download in: http://www.microsoft.com/java/download.htm
Sun provides rudimentary tools for Signing and Verifying
JAR Files at:
http://www.javasoft.com/docs/books/tutorial/jar/sign/index.html (note that
they are not IE or NN compatible)

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gadioCommented:
After the applet is signed, the normal printing scheme should work.
0
 
mapperAuthor Commented:
Here is the code I have so far:

            public void actionPerformed(ActionEvent e) {
                  if(e.getSource() == print) {

                          PrintJob prnJob;
                          Graphics pg = null;
                          try {
                        prnJob = getToolkit().getPrintJob(this, "Printing current frame", null);

                          } catch(Exception ex) {return;}
                        
                          if(prnJob!=null) {
                                    try {
                                        pg = prnJob.getGraphics();
                                    } catch(Exception ex) {return;}
                        }
                              if(pg!=null) {
                                  this.print(pg);
                                  pg.dispose();
                              }
                              prnJob.end();
                  }
                  else if(e.getSource() == exit) {
                        setVisible(false);
                        dispose();
            }
      }
}


I have looked over Gadio's input and that is too much for me to deal with is there any other options available??

Thanks,

mapper
0
 
thresholdCommented:
mapper, gadio is right...
To print in Applet, we have to sign the applet, and if you use Netscape as your browser, you have to use the capabilites api.
There are something we should do for it:

1. sign the applet
2. if you don't want to sign the applet for development, you should enable the codebase principal.
    Find C:\....\Netscape\user\...\prefs.js and add a line (as below) into it.
        user_pref("signed.applets.codebase_principal_support", true);
3. import netscape.security.PrivilegeManager
4. write your java code

  try {
     PrivilegeManager.enablePrivilege("UniversalPropertyRead");
     ps.println("\tSuccess!");
  } catch (netscape.security.ForbiddenTargetException e) {
     ps.println("\tFailed! Permission to read system properties  denied by user.");
  } catch (Exception e) {
     ps.println("\tFailed! Unknown exception while enabling privilege.");
     e.printStackTrace(ps);
  }
 
  PrintJob prnJob;
  Graphics pg = null;
  try {
     prnJob = getToolkit().getPrintJob(this, "Printing current frame", null);
  } catch(Exception ex) {return;}
     if(prnJob!=null) {
  try {
     pg = prnJob.getGraphics();
  } catch(Exception ex) {return;}
  }
   if(pg!=null) {
      this.printAll(pg);  // use the printAll(...) to print frame and its child-component
      pg.dispose();
  }
  prnJob.end();

It's not good idea to print the component on the Screen, because maybe the component contains part of your data. We should create a invisible component as a print page(you can get the page dimension/resolution from printjob), and divide data into several pages , then print them.

If there is any trouble, please open the Java console and post the exceptions here.
0
 
mapperAuthor Commented:
Threshold,

I am not doubting Gadio's input - I guess I did not provide enough information or clarify what I meant well enough - It would be complety acceptable to print from the appletviewer - if that would preclude signing the applet - the code works on two different machines but not mine either at work or at home...

I am trying to figure out why it won't work on mine - I will check the preferences file and see if that has something (basically, look for the line you suggested) peculiar...

Please let me know - if there is something that will make it work in the appletviewer...

And I am sorry if I implied that either Gadio or your information was insuficient...

Thanks,

mapper
0
 
thresholdCommented:
I use the NS4.0x to print document in Java for a while, It's work well always.
but I never use the signed applet in appletviewer.
I can't tell you how to unlock the restriction of security in appletviewer.
Maybe, you can find the document about System.setSecurityManager(...) in JDK1.1.6 to help you.
0
 
gadioCommented:
You have to use the javakey tool for that. You can find documentation in the sun site about the javakey.
0
 
mapperAuthor Commented:
Neither the browser at home or at work - had the line you suggested in the prefs file.  I did check the applet viewer out and set all to "Unrestricted"  that did not help - By "import netscape.security.PrivilegeManager" I am not too clear on what you mean - would that be one of the import lines at the top?  Import netscape.secruity.Privilege manager with the rest of the import calls?  Along with the first part of the code you provided would all of that go into the print method?  I am pretty sure it does but at this point - the frustration level is high an so is the confusion level...

Thanks for sticking with me - I am slow to learn - but that's because I take small bites and I chew each one 75 times!

mapper
0
 
mapperAuthor Commented:
threshold;

I have tried and tried to implement your code and I have had bupkis for luck to get it to compile - the code for me is too hard to figure out - using things I have never used previously....

I need or require some hand holding (I promise I don't kiss on the first date!)...

mapper
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now