org.faceless.pdf2.viewer2
Class PDFViewerApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by org.faceless.pdf2.viewer2.PDFViewerApplet
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, PropertyManager, DocumentPanelListener

public class PDFViewerApplet
extends JApplet
implements DocumentPanelListener, PropertyManager

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.

Since:
2.8
See Also:
Serialized Form

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.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PDFViewerApplet

public PDFViewerApplet()
Method Detail

init

public void init()
Overrides:
init in class Applet

getURLProperty

public URL getURLProperty(String key)
                   throws MalformedURLException
Description copied from interface: PropertyManager
Return the specified property as a URL, or null if no such property is set.

Specified by:
getURLProperty in interface PropertyManager
Throws:
MalformedURLException

getProperty

public String getProperty(String key)
Description copied from interface: PropertyManager
Return the specified property, or null if no such property is set.

Specified by:
getProperty in interface PropertyManager

getAppletInfo

public String getAppletInfo()
Overrides:
getAppletInfo in class Applet

getParameterInfo

public String[][] getParameterInfo()
Overrides:
getParameterInfo in class Applet

loadPDF

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.

Parameters:
url - the URL of the PDF to load.
Throws:
IOException
Since:
2.8.5

loadPDF

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.

Parameters:
url - the URL of the PDF to load.
password - the password to use to open the PDF, or null to prompt if required.
Throws:
IOException
Since:
2.8.6

getViewer

public PDFViewer getViewer()
Return the PDF Viewer embedded in this applet

Since:
2.8.5

runWidgetAction

public void runWidgetAction(String name)
Run the action() method on the specified ViewerWidget. Typically this would be called from JavaScript to move between pages or similar widget-based actions.

Since:
2.8.5

documentUpdated

public void documentUpdated(DocumentPanelEvent event)
Description copied from interface: DocumentPanelListener
Called when an DocumentPanelEvent is raised

Specified by:
documentUpdated in interface DocumentPanelListener


Copyright © 2001-2008 Big Faceless Organization