Thursday, January 19, 2012

How to Display a PDF on JSP page as the part of Applet?

Put this below code in .jspx file
-------------------------------------


-------------------------------------
import java.applet.*;
import java.awt.*;
import java.net.URL;


@author Neelmani Jaiswal * @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://xxx.xx.x.x:xxxx/daw/disp/123.pdf" );
this.getAppletContext().showDocument( url, "_blank" );
} catch (Exception e) {
System.err.println( "Error: Could not display PDF document!" );
}
}
}