Solved

How to open a PDF file from an Applet

Posted on 2001-08-10
8
410 Views
Last Modified: 2006-11-17
Hi

  Could someone give some sample on how to open
a PDF file from an Applet.

Any help is greatly appreciated.

Thanx

Dylan
0
Comment
Question by:dil_line
8 Comments
 
LVL 1

Accepted Solution

by:
dviji earned 50 total points
ID: 6373475
If you want to open the pdf file from the Applet
use AppletContext.showDoumnent("pdf_url","_blank"). It will open that pdf file in a new window... for that same window and some other kinds try with other target attributes in the showdoument() method;

One more possiblity goto www.lowagie.com  and see any API available for pdf reading. [I think I saw some API for PDF generation... ;-))).. ]

Best of luck...

...dviji
0
 

Author Comment

by:dil_line
ID: 6373538
Thanx dviji

        It cannot find showDocument methd. Do I have to import anything ?

Thanx

Dylan
0
 
LVL 92

Expert Comment

by:objects
ID: 6374463
Get it from the getAppletContext() method in Applet
0
 
LVL 2

Expert Comment

by:vasan_sr
ID: 6379110
hi,
  see the code.....
package play.pdf;

import java.applet.*;
import java.awt.*;
import java.net.URL;
/**
 * Demonstrate how to view a PDF document from a Java applet.
 * Makes use of showDocument(), which is described in AppletContext.
 *
 * Assumptions:
 *
 * The applet must be run from a browser, such as Internet Explorer or Netscape Communicator.
 * The browser must have an Adobe Reader plug-in.
 * The technique does not work using appletviewer.
 *
 *
 * This type was created in VisualAge.
 *
 * @author Gerald Hurdle
 * @version 1.0
 */
public class PDFViewer extends Applet {
     Font font = new Font("Dialog", Font.BOLD, 24);
     String str = "PDF Viewer";
     int xPos = 5;
/**
 * Returns information about this applet.
 * @return a string of information about this applet
 */
public String getAppletInfo() {
     return "PDFViewer\n" +
          "\n" +
          "This type was created in VisualAge.\n" +
          "";
}
/**
 * Draws the text on the drawing area.
 * @param g the specified Graphics window
 */
public void paint(Graphics g) {
     g.setFont(font);
     g.setColor(Color.black);
     g.drawString(str, xPos, 50);
}
/**
 * Called to start the applet. You never need to call this method
 * directly, it is called when the applet's document is visited.
 * @see #init
 * @see #stop
 * @see #destroy
 */
public void start() {
     super.start();

     // insert any code to be run when the applet starts here
     try {
          URL url = new URL( "http://www.somecomputer.com/MyPDFDocument.pdf" );
          this.getAppletContext().showDocument( url, "_blank" );
     } catch (Exception e) {
          System.err.println( "Error: Could not display PDF document!" );
     }
}

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:modder
ID: 6489683
Hello all,

dil_line is a duplicate account, and it has been closed.

Please advise as to who should get points for this.

modder
Community Support
0
 
LVL 92

Expert Comment

by:objects
ID: 6489849
I vote for dviji.
0
 
LVL 3

Expert Comment

by:modder
ID: 6489858
OK
0
 
LVL 92

Expert Comment

by:objects
ID: 6489868
Is that how democracy works here at ee :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

930 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

12 Experts available now in Live!

Get 1:1 Help Now