Solved

How to open a PDF file from an Applet

Posted on 2001-08-10
8
409 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
Comment Utility
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
Comment Utility
Thanx dviji

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

Thanx

Dylan
0
 
LVL 92

Expert Comment

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

Expert Comment

by:vasan_sr
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:modder
Comment Utility
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
Comment Utility
I vote for dviji.
0
 
LVL 3

Expert Comment

by:modder
Comment Utility
OK
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Is that how democracy works here at ee :)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mergeTwo  challenge 13 71
Basics of Drool Rule Engine with few samples 2 39
mapShare challenge 13 68
topping1 challenge 7 48
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 Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

15 Experts available now in Live!

Get 1:1 Help Now