|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
org.faceless.pdf2.viewer2.PDFViewerApplet
public class PDFViewerApplet
An applet wrapping the PDFViewer. At it's simplest you can simply embed it in the
page using the applet tag, although since 2.8.5 this class can be usefully
controlled from JavaScript via LiveConnect. For instance, to instantiate an applet
that is controlled via JavaScript buttons instead of Java buttons:
<html>
<head>
<style>
applet { width:100%; height:500px; display:block }
form { text-align:center }
</style>
<script>
function documentUpdated(event) {
if (event.getType()=="redrawn" || event.getType()=="activated") {
document.forms[0].pagenumber.value = event.getDocumentPanel().getPageNumber()+1;
}
}
</script>
</head>
<body>
<applet code="org.faceless.pdf2.viewer2.PDFViewerApplet" name="pdfapplet" archive="bfopdf.jar" mayscript>
<param name="pdf" value="test.pdf" />
<param name="feature.MultiWindow" value="false" />
<param name="feature.Toolbars" value="false" />
<param name="liveconnect.DocumentPanelListener" value="documentUpdated" />
</applet>
<form onsubmit="return false">
<input type="button" onclick="document.pdfapplet.runWidgetAction('PagePrevious')" value="<<"/>
<input type="text" name="pagenumber" size="5"
onchange="document.pdfapplet.getViewer().getActiveDocumentPanel().setPageNumber(this.value-1)"/>
<input type="button" onclick="document.pdfapplet.runWidgetAction('PageNext')" value=">>"/>
</form>
</body>
</html>
Things of note here are the initialization parameters to the applet - the feature.nnn
may be set to false to turn off an individual feature (with nnn being the name or the full class
name of the feature); the pdf attribute is set to load a PDF
from the specified URL on startup; and the liveconnect.DocumentPanelListener attribute is
set to the name of the JavaScript method that should be called whenever a DocumentPanelEvent is raised.
If specified, this method is called with the event object as a single parameter. This also requires the
mayscript attribute on the applet tag as seen here.
Other than that, controlling the applet can be done via the runWidgetAction(java.lang.String) method for simple
widgets or, for more complex operations, the getViewer() method can be used to access and control
the PDFViewer object.
Bear in mind that although the applet is contained in a Signed Jar, any access to that applet from unsigned JavaScript will be untrusted by default - which means no access to the local filesystem, no printing and so on (although it is possible to sign the JavaScript to allow this).
This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JApplet |
|---|
JApplet.AccessibleJApplet |
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JApplet |
|---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface org.faceless.pdf2.PropertyManager |
|---|
SYSTEM |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
PDFViewerApplet()
|
|
| Method Summary | |
|---|---|
void |
documentUpdated(DocumentPanelEvent event)
Called when an DocumentPanelEvent is raised |
String |
getAppletInfo()
|
String[][] |
getParameterInfo()
|
String |
getProperty(String key)
Return the specified property, or null if no such
property is set. |
URL |
getURLProperty(String key)
Return the specified property as a URL, or null if no
such property is set. |
PDFViewer |
getViewer()
Return the PDF Viewer embedded in this applet |
void |
init()
|
void |
loadPDF(String url)
Load a PDF from the specified URL. |
void |
loadPDF(String url,
String password)
Load a PDF from the specified URL. |
void |
runWidgetAction(String name)
Run the action() method on the specified
ViewerWidget. |
| Methods inherited from class javax.swing.JApplet |
|---|
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update |
| Methods inherited from class java.applet.Applet |
|---|
destroy, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public PDFViewerApplet()
| Method Detail |
|---|
public void init()
init in class Applet
public URL getURLProperty(String key)
throws MalformedURLException
PropertyManagernull if no
such property is set.
getURLProperty in interface PropertyManagerMalformedURLExceptionpublic String getProperty(String key)
PropertyManagernull if no such
property is set.
getProperty in interface PropertyManagerpublic String getAppletInfo()
getAppletInfo in class Appletpublic String[][] getParameterInfo()
getParameterInfo in class Applet
public void loadPDF(String url)
throws IOException
Load a PDF from the specified URL. If the URL is relative, it is resolved
based on the URL of the page containing the applet. Simply calls
loadPDF(url, null).
Bear in mind if that any methods, including this one, that are called from JavaScript will run as if the applet was untrusted. Consequently this method cannot be called to load PDF's from the local filesystem.
url - the URL of the PDF to load.
IOException
public void loadPDF(String url,
String password)
throws IOException
Load a PDF from the specified URL. If the URL is relative, it is resolved
based on the URL of the page containing the applet. If the password
parameter is not null then that password will be used if required, otherwise
any required passwords or private keys will be prompted for - for finer control, the PDFViewer.loadPDF()
method can be used.
Bear in mind if that any methods, including this one, that are called from JavaScript will run as if the applet was untrusted. Consequently this method cannot be called to load PDF's from the local filesystem.
url - the URL of the PDF to load.password - the password to use to open the PDF, or null to prompt if required.
IOExceptionpublic PDFViewer getViewer()
public void runWidgetAction(String name)
action() method on the specified
ViewerWidget. Typically this would be called from JavaScript to move
between pages or similar widget-based actions.
public void documentUpdated(DocumentPanelEvent event)
DocumentPanelListenerDocumentPanelEvent is raised
documentUpdated in interface DocumentPanelListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||