Please choose a menu option
Visit the IDRsolutions WebSite

Setup and run a Java PDF applet viewer

PDF files can be viewed in a Java Applet using JPedal. The SimpleViewer example can be run as an applet from a web page with no modifications. Click here to open an example page with a PDF applet viewer.

 

Important note

You should use the signed jar if you wish to run JPedal as an Applet

 

Sample code

To run JPedal as an applet, add the following code to your HTML page. While it is possible to use the <applet></applet> tags, these have been deprecated by W3C.

The code beneath uses the <object></object> tags, and makes use of IE's conditional commenting to make it cross browser compatible. Many thanks to Shayne Steele from Florida State University for working out the tweaks needed for this code to function.

<!--[if !IE]> Firefox and others will use outer object -->
<object align="center" height=95% width=95%
classid="java:org.jpedal.examples.simpleviewer.AppletViewer"
type="application/x-java-applet"
archive="http://www.jpedal.org/download/jpedal.jar,
http://www.jpedal.org/download/jars/bc.jar,
http://www.jpedal.org/download/jars/itext-1.3.jar" >
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object align="center" height=95% width=95%
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93">
<param name="archive" value="download/jpedal.jar,
download/jars/bc.jar, download/jars/itext-1.3.jar">
<param name="code" value="org.jpedal.examples.simpleviewer.AppletViewer">
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->

 

Notes on the sample code

  • The clsid in the IE code will use the latest installed version of Java.
  • The IE conditional commenting will ensure IE does not try to run the Firefox object.
  • As Firefox does not recognise the clsid tag, it will not try to run the IE object.

 

Assigning more memory

Sometimes you need more memory to display a PDF file. You can increase this using this code (512Megabytes of memory in this example). Click here for a useful guide on using this to set general parameters.

<param name="java_arguments" value="-Xmx512m">

 

Specifying a default file

It is possible to specify a default file using a 'param' tag. This should be placed in both your inner and outer objects.

<param name="openURL" value="http://www.jpedal.org/jpedal.pdf">

 

Loading a properties file

It is possible to specify a properties file to load using a 'param' tag by specifying the absolute file name of the file you wish to use. This should be placed in both your inner and outer objects.

<param name="propertiesFile" value="C:\Users\IDRSolutions\Documents\properties.xml">

You can set the memory mode directly in the HTML with this command

<param name="org.jpedal.memory" value="true">

 

Calling from JavaScript

It is also possible to call various viewer functions from JavaScript. A tutorial is available here.

 

Note on jars not used

In the interests of speed, some jars have been left off the demo. They may be required for some PDF files. See Additional optional libraries for full details.

 

Links to related articles

Getting started tutorial
JVM options available on startup which can customise memory usage, image quality and lots of other settings.
Demo of drag and drop functionality in PDF Viewer (works on applet).
AppletViewer - provides a version of SimpleViewer running as an Applet
Additional optional libraries lists items which may be needed for some PDFs or functionality.

 

Return to main PDF support section

Click here for the main PDF support area with lots of java examples, PDF tutorials and useful information to get the most out of the JPedal PDF library

 


PDF viewer