Go Premium for a chance to win a PS4. Enter to Win

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

How to open a PDF file from an Applet

Hi

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

Any help is greatly appreciated.

Thanx

Dylan
0
dil_line
Asked:
dil_line
1 Solution
 
dvijiCommented:
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
 
dil_lineAuthor Commented:
Thanx dviji

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

Thanx

Dylan
0
 
objectsCommented:
Get it from the getAppletContext() method in Applet
0
Technology Partners: 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!

 
vasan_srCommented:
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
 
modderCommented:
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
 
objectsCommented:
I vote for dviji.
0
 
modderCommented:
OK
0
 
objectsCommented:
Is that how democracy works here at ee :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now