|
||||||||||
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()=="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:
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.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)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.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.
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.
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 |
destroy()
|
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 |
---|
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 void destroy()
destroy
in class Applet
public URL getURLProperty(String key) throws MalformedURLException
PropertyManager
null
if no
such property is set.
getURLProperty
in interface PropertyManager
MalformedURLException
public String getProperty(String key)
PropertyManager
null
if no such
property is set.
getProperty
in interface PropertyManager
public String getAppletInfo()
getAppletInfo
in class Applet
public 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.
IOException
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.
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
IOException
public 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)
DocumentPanelListener
DocumentPanelEvent
is raised
documentUpdated
in interface DocumentPanelListener
public void appletDragStarted()
public void appletDragFinished()
public void setAppletCloseListener(ActionListener listener)
listener
- the listener to be called when the window is closedpublic void appletRestored()
public boolean isDraggedFromBrowser()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |