Solved

How to open a PDF file from an Applet

Posted on 2001-08-10
8
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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!

 
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
 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 47
Error in @AspectJ Based AOP with Spring 2 23
American Express @Work site and Java 4 63
Html split(text) 2 27
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

762 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