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()=="pageChanged") {
        document.forms[0].pagenumber.value = event.getDocumentPanel().getPageNumber()+1;
      }
    }
   </script>
  </head>
  <body>
   <applet code="org.faceless.pdf2.viewer2.PDFViewerApplet" name="pdfapplet" archive="bfopdf.jar, bfopdf-cmap.jar">
    <param name="pdf" value="test.pdf" />1
    <!-- <param name="password" value="secret" /> -->
    <param name="feature.MultiWindow" value="false" />2
    <param name="feature.Toolbars" value="false" />
    <param name="feature.ThumbnailPanel.editable" value="false" />3
    <param name="liveconnect.DocumentPanelListener" value="documentUpdated" />4
    <!-- following parameters improve the experience under Java 1.6u10 -->
    <param name="jnlp_href" value="bfopdf-applet.jnlp" /> <!-- see below -->5
    <param name="draggable" value="true" />
    <param name="image" value="http://bfo.com/external/loading.gif" />
    <param name="boxborder" value="false" />
    <param name="centerimage" value="true" />
    <param name="separate_vm" value="true" /> <!-- optional -->
   </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 pdf attribute may be set to load a PDF from the specified URL on startup. Multiple PDFs can be loaded at once by specifying the pdf2, pdf3 etc. parameters, and if passwords are needed to open those PDFs they can be specified with the corresponding password, password2 etc. parameters. Likewise the filename, filename2 etc. parameters can be set to initialize the filename of those PDFs.
  • 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 feature.nnn.mmm may be specified to set a specific initialization parameter on a feature. The parameters that apply to an individual class are documented in the API docs for that class.
  • 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.
  • the Java 1.6u10 parameters, in particular the "jnlp_href" attribute: This optional parameter refers to a JNLP file which is used to provide more information to the Java plugin, including information that allows the download of Jar files to be optimized. This parameter is ignored by older JVMs, and so is worth including to improve the experience for people using the latest JVM. We provide a sample JNLP file as "bfopdf-applet.jnlp" as part of the distribution. The remaining parameters can be used exactly as above or altered as you see fit. There's more information on the new Java plug-in at java.net
  • 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.

    Remember 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 appletDragFinished()
              Called by the JRE in 1.6u10 after the Applet has been dragged onto the Desktop
     void appletDragStarted()
              Called by the JRE in 1.6u10 when the Applet is being dragged onto the Desktop
     void appletRestored()
              Called by the JRE in 1.6u10 when the applet has been closed as a standalone application, indicating the applet has been returned to its location inside the browser.
     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()
               
     boolean isDraggedFromBrowser()
              Return flag indicating if we're running outside the browser or not
     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 loadPDF(String url, String password, File savefile)
               Load a PDF from the specified URL.
     void runWidgetAction(String name)
              Run the action() method on the specified ViewerWidget.
     void setAppletCloseListener(ActionListener listener)
              Called by the JRE in 1.6u10, this method signifies that we're drawing our own close button.
     
    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

    loadPDF

    public void loadPDF(String url,
                        String password,
                        File savefile)
                 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.
    savefile - the default file to use if the PDF is saved after opening. May be null
    Throws:
    IOException
    Since:
    2.11.22

    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

    appletDragStarted

    public void appletDragStarted()
    Called by the JRE in 1.6u10 when the Applet is being dragged onto the Desktop

    Since:
    2.11.1

    appletDragFinished

    public void appletDragFinished()
    Called by the JRE in 1.6u10 after the Applet has been dragged onto the Desktop

    Since:
    2.11.1

    setAppletCloseListener

    public void setAppletCloseListener(ActionListener listener)
    Called by the JRE in 1.6u10, this method signifies that we're drawing our own close button.

    Parameters:
    listener - the listener to be called when the window is closed
    Since:
    2.11.1

    appletRestored

    public void appletRestored()
    Called by the JRE in 1.6u10 when the applet has been closed as a standalone application, indicating the applet has been returned to its location inside the browser.

    Since:
    2.11.1

    isDraggedFromBrowser

    public boolean isDraggedFromBrowser()
    Return flag indicating if we're running outside the browser or not

    Since:
    2.11.1


    Copyright © 2001-2010 Big Faceless Organization