com.qoppa.pdfViewer
Class PDFViewerBean
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.qoppa.pdfViewer.PDFViewerBean
- All Implemented Interfaces:
- Accessible, ActionListener, EventListener, IDocumentListener, ImageObserver, IPassword, IPDFActionHandler, IPDFOpener, KeyListener, MenuContainer, Serializable
- public class PDFViewerBean
- extends JPanel
- implements KeyListener, ActionListener, IPassword, IDocumentListener, IPDFActionHandler, IPDFOpener
PDFViewer bean is a component that can be used to display
PDF documents within an application or an applet. The bean
takes a PDF document as a file name, a URL or an InputStream,
reads the document and then displays the document, allowing
the user to navigate through the document.
- Author:
- Qoppa Software
- See Also:
- Serialized Form
|
Method Summary |
void |
actionPerformed(ActionEvent e)
Handles toolbar actions. |
void |
addAnnotationToSelection(Annotation annot)
Adds the given Annotation's component to the list of selected components. |
void |
clearDocument()
Clears any loaded document. |
void |
closeTextSearch()
Closes the text search box. |
void |
deselectAnnotation(Annotation annot)
Removes the given Annotation's component to the list of selected components. |
void |
documentChanged(DocumentEvent de)
Internal method, do not use. |
AcroForm |
getAcroForm()
Returns the AcroForm in this document. |
AnnotationManager |
getAnnotationManager()
Returns the object that manages annotation selection for this viewer. |
AttachmentPanel |
getAttachmentPanel()
Returns an interface to allow access to the attachment panel. |
BookmarkPanel |
getBookmarkPanel()
Returns an interface to allow access to the bookmarks panel. |
CommentPanel |
getCommentPanel()
Returns an interface to allow access to the comment panel. |
GotoPageAction |
getCurrentLocation()
Returns the current location of the viewer as a GotoPageAction. |
IPDFDocument |
getDocument()
Returns the PDF document currently displayed. |
InitialViewSettings |
getInitialViewSettings()
Returns the InitialViewSettings object that specifies what
page mode, page layout, and magnification values should be used when opening
a document. |
LayerPanel |
getLayerPanel()
Returns an interface to allow access to the layer panel. |
int |
getPageByLocation(int x,
int y)
Returns the index of a page given an x, y location on the document. |
int |
getPageCount()
Returns the number of pages in the current document. |
int |
getPageMode()
Returns the page viewing mode for viewer. |
int |
getPageNumber()
Returns the currently displayed page. |
JComponent |
getPageView(int pageNumber)
Returns the page view component for the given page number. |
PageViewPanel |
getPageViewPanel()
Returns an interface to allow access to the page view panel. |
IPassword |
getPasswordHandler()
Returns the currently registered password handler. |
String[] |
getPasswords()
Standard implementation of the password handler. |
JRootPane |
getRootPane()
Returns a reference to the PDFViewerBean root pane. |
int |
getRotation()
Returns the current rotation. |
int |
getScale()
Deprecated. use PDFViewerBean.getScale2D() |
double |
getScale2D()
Returns the current scale used to display the PDF document in double precision. |
JScrollPane |
getScrollPane()
Returns a reference to the PDFViewerBean scroll pane. |
TextSelection |
getSelectedText()
Gets the current text selection (if any page has selected text) in the document. |
TextSelectionContextMenu |
getSelectTextContextMenu()
Deprecated. Use getPageViewPanel.getTextSelectionContextMenu() |
SelectToolbar |
getSelectToolbar()
Returns the selection toolbar. |
SignaturePanel |
getSignaturePanel()
Returns an interface to allow access to the signature panel. |
int |
getSplitPolicy()
Deprecated. This feature has been replaced by the InitialViewSettings class.
|
ThumbnailPanel |
getThumbnailPanel()
Returns an interface to allow access to the thumbnail panel. |
PDFToolbar |
getToolbar()
Returns the navigation toolbar. |
ButtonGroup |
getToolbarButtonGroup()
Returns a reference to the button group used to toggle some of the tools in the toolbar. |
static String |
getVersion()
Returns version string for jPDFViewer. |
PageViewContextMenu |
getViewerContextMenu()
Deprecated. Use getPageViewPanel.getPageContextMenu() |
int |
getZoomMode()
Get the current zoom mode. |
void |
gotoNextView()
PDFViewer maintains a history of page views. |
void |
gotoPreviousView()
PDFViewer maintains a history of page views. |
void |
handleAction(Action action)
This method will handle PDF actions initiated by a click on
a link. |
boolean |
isAttachmentsTabSelected()
returns true if the attachments tab is selected |
boolean |
isBookmarksTabSelected()
returns true if the bookmarks tab is selected |
boolean |
isCommentsTabSelected()
returns true if the comments tab is selected |
boolean |
isCommentsVisible()
Returns whether comments are visible on the component. |
boolean |
isFieldsHighlight()
Returns whether or not the fields should be highlighted. |
boolean |
isLayersTabSelected()
returns true if the layers tab is selected |
boolean |
isPagesTabSelected()
returns true if the pages tab is selected |
boolean |
isSignaturesTabSelected()
returns true if the signatures tab is selected |
boolean |
isSplitOpen()
Returns whether the split window is open or not. |
void |
keyPressed(KeyEvent e)
Handle key pressed events. |
void |
keyReleased(KeyEvent e)
Fullfill the KeyListener interfaces. |
void |
keyTyped(KeyEvent e)
Fullfill the KeyListener interfaces. |
void |
loadPDF(InputStream inStream)
Load and display a PDF document using an InputStream. |
void |
loadPDF(PDFSource source)
Load and display a PDF document using an object that implements PDFSource. |
void |
loadPDF(String fileName)
Load and display a PDF document using a file name. |
void |
loadPDF(URL url)
Load and display a PDF document using a URL. |
void |
openFile()
Initiates the file open process. |
void |
openFile(PDFViewerBean viewerBean)
Initiates the file open process. |
void |
print(PrintSettings printSettings)
Prints the PDF document to a printer. |
void |
rotateCCW()
Rotates pages 90 degrees counter-clockwise. |
void |
rotateCW()
Rotates pages 90 degrees clockwise. |
void |
scrollToAnnotation(Annotation annot)
If annot is not visible, this method will scroll to it. |
void |
scrollToPage(int pageNumber,
int x,
int y)
Scroll to the given page and make sure that point (x,y) is visible on the page by scrolling to it if needed. |
void |
selectAnnotation(Annotation annot)
Selects the given Annotation's component. |
static boolean |
setAppletKey(String key,
Applet applet)
Sets product key when running jPDFViewer in an applet. |
void |
setCommentComponentsVisible(boolean visible)
This method will set hiding of comments components on and off. |
void |
setCommentsVisible(boolean visible)
This method will turn viewing of comments on or off. |
void |
setDocument(IPDFDocument pdfDoc)
Sets this bean's document. |
void |
setFieldsHighlight(boolean highlight)
Highlight any fields in the document. |
void |
setHorzDividerLocation(int location)
Sets the location, in pixels, of the horizontal divider. |
static boolean |
setKey(String key)
Sets product key. |
void |
setPage(int pageNumber)
Changes the currently displayed page. |
void |
setPageMode(int pageMode)
Sets the page viewing mode in the viewer. |
void |
setPasswordHandler(IPassword pwdHandler)
Override the standard password handler with a user
password handler. |
void |
setPDFOpener(IPDFOpener opener)
Sets the PDF opener for this bean. |
void |
setPrintSettings(PrintSettings printSettings)
Sets the print settings to be used when the print button is
activated from the toolbar. |
void |
setRotation(int rotation)
Sets the current rotation. |
void |
setScale(int scale)
Deprecated. - Use setScale2D() |
void |
setScale2D(double scale)
Changes the display scale for the PDF document. |
void |
setSnapshotHandler(ISnapshotHandler handler)
By default, the PDFViewerBean will place the BufferedImage in the system clipboard. |
void |
setSplitOpen(boolean splitOpen)
Opens or closes the split window. |
void |
setSplitPolicy(int splitPolicy)
Sets the viewer's split window policy. |
void |
setSplitVisible(boolean visible,
boolean open)
Method to show / hide the split pane functionality. |
void |
setTabCommentsVisible(boolean visible)
This method will set the visibility of the comments panel. |
static void |
setTextSelectionColors(Color xorColor,
Color fgndColor)
Set the colors used to highlight text on search results. |
void |
setVertDividerLocation(int location)
Sets the location, in pixels, of the vertical divider. |
void |
setZoomMode(int zoomMode)
Sets the current zoom mode. |
void |
showError(String msg,
Throwable t)
Convenience method to display an error message. |
void |
showMessage(String msg)
Convenience method to display a message using this PDFViewerBean as the message dialog's parent. |
void |
showTabAttachments()
This methods will ensure that the file attachment tab is showing. |
void |
showTabBookmarks()
This methods will ensure that the bookmarks tab is showing. |
void |
showTabLayers()
This methods will ensure that the layers tab tab is showing. |
void |
showTabSignature()
This methods will ensure that the signature tab tab is showing. |
void |
showTabThumbnails()
This methods will ensure that the thumbnails tab is showing. |
void |
startLoupeTool()
This method activates the loupe tool. |
void |
startMagnifyRect()
This method activates the magnification rectangle tool. |
void |
startTextSearch()
This method starts the text searching process. |
void |
startTextSearch(String search)
This method shows the text search dialog and tells it to search for a string. |
void |
startTextSelection()
This methods activates the text selection tool. |
void |
stopTextSelection()
This method stops the text selection tool and activates the "hand" tool. |
void |
zoomToRect(Rectangle2D zoomRect)
Zooms the viewer to a particular rectangle on the document. |
| Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate |
| Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
SPLITPOLICY_USEDOCUMENTPAGEMODE
public static final int SPLITPOLICY_USEDOCUMENTPAGEMODE
- Use the setting inside the PDF document to determine the visibility of the split pane. A PDF document can contain
a setting that tells a viewer whether to show the page thumbnails, document outline or other panes. When the split
policy in jPDFViewer is set to this value, the viewer will read and use this setting. This is the default setting.
- See Also:
- Constant Field Values
SPLITPOLICY_NEVER_VISIBLE
public static final int SPLITPOLICY_NEVER_VISIBLE
- Never show the split pane.
- See Also:
- Constant Field Values
ZOOMMODE_NORMAL
public static final int ZOOMMODE_NORMAL
- Normal zoom mode means that the scale remains the same when the window is resized.
- See Also:
- Constant Field Values
ZOOMMODE_FITPAGE
public static final int ZOOMMODE_FITPAGE
- FitPage zoom mode changes the scale when the window is resized so that the page
is displayed using the maximum available space.
- See Also:
- Constant Field Values
ZOOMMODE_FITWIDTH
public static final int ZOOMMODE_FITWIDTH
- FitWidth zoom mode changes the scale when the window is resized so that the full
width of the page is displayed using the maximum available space.
- See Also:
- Constant Field Values
PAGEMODE_CONTINUOUS
public static final int PAGEMODE_CONTINUOUS
- Continuous page display mode. All pages are visible and can scroll across
pages using the scroll bar and the hand tool.
- See Also:
- Constant Field Values
PAGEMODE_SINGLEPAGE
public static final int PAGEMODE_SINGLEPAGE
- Single page display mode. Only one page is visible at a time. The hand
tool and scroll bar will not go across pages, user needs to use the next
and previous page buttons to do this.
- See Also:
- Constant Field Values
PAGEMODE_FACING
public static final int PAGEMODE_FACING
- Facing pages display mode. Two pages are displayed next to each other. The hand tool and scroll
bar will not move to the next two pages, only the next and previous page buttons will go
up and down the document, two pages at a time.
- See Also:
- Constant Field Values
PAGEMODE_FACING_CONTINUOUS
public static final int PAGEMODE_FACING_CONTINUOUS
- Continuous facing pages display mode. Two pages are displayed next to each other, and all pages
in the document are displayed. Hand tool and scroll bar can be used to move up and down the
document as well as the next and previous page buttons.
- See Also:
- Constant Field Values
PDFViewerBean
public PDFViewerBean()
- Construct the PDFViewerBean.
setDocument
public void setDocument(IPDFDocument pdfDoc)
- Sets this bean's document. When this method is called, the bean will go back to page 1 of the
document and reset the page control in the toolbar. The method will also start generating a new
set of thumbviews for the pages.
- Parameters:
pdfDoc - The new document.
isAttachmentsTabSelected
public boolean isAttachmentsTabSelected()
- returns true if the attachments tab is selected
isBookmarksTabSelected
public boolean isBookmarksTabSelected()
- returns true if the bookmarks tab is selected
isCommentsTabSelected
public boolean isCommentsTabSelected()
- returns true if the comments tab is selected
isLayersTabSelected
public boolean isLayersTabSelected()
- returns true if the layers tab is selected
isPagesTabSelected
public boolean isPagesTabSelected()
- returns true if the pages tab is selected
isSignaturesTabSelected
public boolean isSignaturesTabSelected()
- returns true if the signatures tab is selected
showTabBookmarks
public void showTabBookmarks()
- This methods will ensure that the bookmarks tab is showing. It will first ensure that the splitpane
is open and visible and then select the bookmarks tab.
showTabThumbnails
public void showTabThumbnails()
- This methods will ensure that the thumbnails tab is showing. It will first ensure that the splitpane
is open and visible and then select the thumbnails tab.
setTabCommentsVisible
public void setTabCommentsVisible(boolean visible)
- This method will set the visibility of the comments panel.
- Parameters:
visible - The new visibility state.
setCommentsVisible
public void setCommentsVisible(boolean visible)
- This method will turn viewing of comments on or off. When viewing is turned off,
the comments pane will not be visible or accessible and the comments will not be
shown on the component.
- Parameters:
visible - Comment visibility flag
setCommentComponentsVisible
public void setCommentComponentsVisible(boolean visible)
- This method will set hiding of comments components on and off.
When false, comment components will be dynamically hidden.
Comments will still show in the comment pane, but will not
be displayed in the viewer. They will also not be rendered
when printing.
When true, comment components will be displayed as normal.
- Parameters:
visible - Comment visibility flag
isCommentsVisible
public boolean isCommentsVisible()
- Returns whether comments are visible on the component.
showTabAttachments
public void showTabAttachments()
- This methods will ensure that the file attachment tab is showing. It will first ensure that the splitpane
is open and visible and then select the file attachment tab.
showTabSignature
public void showTabSignature()
- This methods will ensure that the signature tab tab is showing. It will first ensure that
the split pane is open and visible and then select the signature tab.
showTabLayers
public void showTabLayers()
- This methods will ensure that the layers tab tab is showing. It will first ensure that
the split pane is open and visible and then select the layers tab.
handleAction
public void handleAction(Action action)
- This method will handle PDF actions initiated by a click on
a link. If the action is a URL, the method will open a new
browser window to show the link. If the action is to launch
a file, the method will call the operating system to open
the file with the registered program.
This method can be overridden to handle actions in a custom
manner. The parameter passed in will be an instance of an
object derived from Action and can be tested using 'instanceof'
to determine the kind of action.
- Specified by:
handleAction in interface IPDFActionHandler
- Parameters:
action - Object describing the action.
getAcroForm
public AcroForm getAcroForm()
- Returns the AcroForm in this document. Returns null if the document has no fields.
Use this method to get a reference to a PDF document's AcroForm to be able to get
and set field data.
- Returns:
- AcroForm The AcroForm object for this document.
getDocument
public IPDFDocument getDocument()
- Returns the PDF document currently displayed.
- Returns:
- The current document.
loadPDF
public void loadPDF(URL url)
throws PDFException
- Load and display a PDF document using a URL.
- Parameters:
url - URL pointing to the location of the PDF document.
- Throws:
PDFException
loadPDF
public void loadPDF(PDFSource source)
throws PDFException
- Load and display a PDF document using an object that implements PDFSource.
- Parameters:
source - Object that implements the PDFSource interface.
- Throws:
PDFException
clearDocument
public void clearDocument()
- Clears any loaded document.
loadPDF
public void loadPDF(InputStream inStream)
throws PDFException
- Load and display a PDF document using an InputStream.
- Parameters:
inStream - InputStream used to read the PDF document.
- Throws:
PDFException
loadPDF
public void loadPDF(String fileName)
throws PDFException
- Load and display a PDF document using a file name.
- Parameters:
fileName - Name of the PDF document file.
- Throws:
PDFException
setScale
public void setScale(int scale)
- Deprecated. - Use setScale2D()
- Changes the display scale for the PDF document.
- Parameters:
scale - Magnification factor as a percentage. 100 is true size.
setScale2D
public void setScale2D(double scale)
- Changes the display scale for the PDF document.
- Parameters:
scale - Magnification factor as a percentage. 100 is true size.
getScale
public int getScale()
- Deprecated. use PDFViewerBean.getScale2D()
- Returns the current scale used to display the PDF document rounded down to
the nearest integer
- Returns:
- Current display scale.
getScale2D
public double getScale2D()
- Returns the current scale used to display the PDF document in double precision.
- Returns:
- Current display scale.
getToolbar
public PDFToolbar getToolbar()
- Returns the navigation toolbar. Host applications can use this method
to be able to change the behaviour of the toolbar, such as making buttons
visible/invisible, adding listeners, etc. Please see PDFToolbar for
details.
- Returns:
- The bean's toolbar.
getSelectToolbar
public SelectToolbar getSelectToolbar()
- Returns the selection toolbar. This toolbar has three icons, the hand icon to allow users to drag
the document around with the mouse, the text select icon to let the user select text in the
document, and the snapshot icon to allow users to capture an image. As with the navigation toolbar,
the host application can choose not to show this toolbar by calling getSelectToolbar().setVisible (false).
- Returns:
- Reference to the selection toolbar.
actionPerformed
public void actionPerformed(ActionEvent e)
- Handles toolbar actions. This method is necessary to implement the ActionListener
interface. The bean is registered with all buttons in the toolbar to handle their
actions. A derived class can override this method to customize the behavior of the
toolbar buttons.
- Specified by:
actionPerformed in interface ActionListener
- Parameters:
e - The action event.
setSnapshotHandler
public void setSnapshotHandler(ISnapshotHandler handler)
- By default, the PDFViewerBean will place the BufferedImage in the system clipboard. The host
application can provide custom functionality by setting a different handler for the snapshot tool.
- Parameters:
handler - ISnapshotHandler implementation
getRotation
public int getRotation()
- Returns the current rotation.
- Returns:
- The bean's current rotation in degrees, valid values are 0, 90, 180 and 270.
setRotation
public void setRotation(int rotation)
- Sets the current rotation. Valid values are only 0, 90, 180 and 270.
- Parameters:
rotation - Rotation angle in degrees.
rotateCW
public void rotateCW()
- Rotates pages 90 degrees clockwise.
rotateCCW
public void rotateCCW()
- Rotates pages 90 degrees counter-clockwise.
openFile
public void openFile()
throws PDFException
- Initiates the file open process. This method is normally called when a user presses the open file
button in the toolbar but can also be called programmatically by the host application. The method
will call the currently registered pdf opener to prompt the user to choose a file. The default
pdf opener shows a file chooser dialog to allow the user to choose a file on the local drives.
- Throws:
PDFException
openFile
public void openFile(PDFViewerBean viewerBean)
throws PDFException
- Initiates the file open process. This method fulfills the IPDFOpener interface and is the default
implementation of a PDF opener. The method shows a file chooser dialog to let the user choose a file.
- Specified by:
openFile in interface IPDFOpener
- Parameters:
viewerBean - The PDFViewerBean object that initiated the open file action.
- Throws:
PDFException
getPageNumber
public int getPageNumber()
- Returns the currently displayed page.
- Returns:
- int Currently displayed page.
getPageView
public JComponent getPageView(int pageNumber)
- Returns the page view component for the given page number. The method returns an object of type JComponent,
but this object is also guaranteed to implement IPDFPageView, so it can be casted without problems.
- Parameters:
pageNumber - Number of the page to return. Pages are indexed starting at 1.
- Returns:
- JComponent Reference to a component object that displays the given page. null if the pageNumber is out of range.
getPageCount
public int getPageCount()
- Returns the number of pages in the current document.
- Returns:
- int Number of pages in the PDF document.
getPasswords
public String[] getPasswords()
- Standard implementation of the password handler. This
method shows a simple dialog with a password field to allow
the user to enter a password.
The standard password handler can be overridden by calling
setPasswordHandler
- Specified by:
getPasswords in interface IPassword
- Returns:
- byte array containing the password.
print
public void print(PrintSettings printSettings)
throws PDFPermissionException,
PrinterException
- Prints the PDF document to a printer. This method will first
prompt the user to choose a system printer and then it will
print the document.
If finer control of printing is necessary, the IPDFDocument object
return by the getDocument() method implements both Printable and
Pageable. The host application can then create its own PrinterJob
and set any settings necessary, then call either setPageable or
setPrintable with the IPDFDocument object and then start the print
job.
- Parameters:
printSettings - Print job settings. Use this object to tell
jPDFViewer how to print the document. If null, the library will
print using default settings.
- Throws:
PDFPermissionException
PrinterException
setPrintSettings
public void setPrintSettings(PrintSettings printSettings)
- Sets the print settings to be used when the print button is
activated from the toolbar. The print settings will be cloned
so that any modifications to the PrintSettings object will not
be reflected when printing.
- Parameters:
printSettings - Print job settings. Use this object to tell
jPDFViewer how to print the document.
setPage
public void setPage(int pageNumber)
- Changes the currently displayed page.
- Parameters:
pageNumber - Page to display. Pages are indexed starting at 1.
getVersion
public static String getVersion()
- Returns version string for jPDFViewer. If this is the demo version,
the return string will contain 'Demo Version' at the end.
setPasswordHandler
public void setPasswordHandler(IPassword pwdHandler)
- Override the standard password handler with a user
password handler. If a document is password protected,
jPDFViewer will call the password handler to obtain
a password.
- Parameters:
pwdHandler - User object that implements IPasswordHandler.
setPDFOpener
public void setPDFOpener(IPDFOpener opener)
- Sets the PDF opener for this bean. The PDF opener gets called whenever a user clicks on the open
button on the toolbar. By default, PDFViewerBean implements IPDFOpener by showing a file dialog
that lets the user choose a local file. The host application can choose to override this to
show a custom opener, for cases where documents might come from the web, or other locations.
- Parameters:
opener - The new object that implements IPDFOpener
getPasswordHandler
public IPassword getPasswordHandler()
- Returns the currently registered password handler. The password handler
is used when the library opens a document that is protected by passwords.
- Returns:
- The current password handler.
setKey
public static boolean setKey(String key)
- Sets product key. Use this method after purchasing to remove
evaluation restrictions.
- Parameters:
key - Product key.
setAppletKey
public static boolean setAppletKey(String key,
Applet applet)
- Sets product key when running jPDFViewer in an applet. Use this method after purchasing to remove
evaluation restrictions.
- Parameters:
key - Product key.applet - The applet that we are running in.
setSplitVisible
public void setSplitVisible(boolean visible,
boolean open)
- Method to show / hide the split pane functionality.
When visible, the left side of the bean will show thumbnails, comments, bookmarks
and layers in the PDF file.
When not visible, thumbnails, comments, bookmarks and layers will not be displayed
to the user and the split bar functionality goes away.
- Parameters:
visible - The new split pane visibility.open - Determines whether the split pane should be open or closed
isSplitOpen
public boolean isSplitOpen()
- Returns whether the split window is open or not.
- Returns:
- Open state of the split window.
setSplitOpen
public void setSplitOpen(boolean splitOpen)
- Opens or closes the split window.
- Parameters:
splitOpen - Desired open state of the split window.
setVertDividerLocation
public void setVertDividerLocation(int location)
- Sets the location, in pixels, of the vertical divider. This is the divider that separates
the thumbnail and bookmark panes on the left to the content pane on the right.
- Parameters:
location - The new location for the divider.
setHorzDividerLocation
public void setHorzDividerLocation(int location)
- Sets the location, in pixels, of the horizontal divider. This is the divider that separates
the comments pane at the bottom to the content pane on the top.
- Parameters:
location - THe new location for the divider.
selectAnnotation
public void selectAnnotation(Annotation annot)
- Selects the given Annotation's component. If the Annotation's component is
not visible, the PDFViewerBean will first scroll to ensure that it is,
and then select the component.
- Parameters:
annot - the Annotation to select
scrollToAnnotation
public void scrollToAnnotation(Annotation annot)
- If annot is not visible, this method will scroll to it.
- Parameters:
annot - the Annotation to select
addAnnotationToSelection
public void addAnnotationToSelection(Annotation annot)
- Adds the given Annotation's component to the list of selected components.
If the list is currently empty and the component is not visible, the viewbean
will scroll to it. If an annotation is already selected, no scroll will occur.
- Parameters:
annot - the Annotation to select
deselectAnnotation
public void deselectAnnotation(Annotation annot)
- Removes the given Annotation's component to the list of selected components.
- Parameters:
annot - the Annotation to select
scrollToPage
public void scrollToPage(int pageNumber,
int x,
int y)
- Scroll to the given page and make sure that point (x,y) is visible on the page by scrolling to it if needed.
(x,y) are given in crop box coordinates, the crop box being the visible area of the page.
- Parameters:
pageNumber - the page number starting at 1.x - the horizontal position to scroll to on the pagey - the vertical position to scroll to on the page
documentChanged
public void documentChanged(DocumentEvent de)
- Internal method, do not use.
- Specified by:
documentChanged in interface IDocumentListener
getScrollPane
public JScrollPane getScrollPane()
- Returns a reference to the PDFViewerBean scroll pane. Use this method
when finer control of the scroll pane and scroll behaviour is need.
- Returns:
- The scroll pane used inside the PDFViewerBean.
getRootPane
public JRootPane getRootPane()
- Returns a reference to the PDFViewerBean root pane. The document is displayed
within a root pane that is then added to a scroll pane. Use this method when
finer control of the root pane is needed.
getSplitPolicy
public int getSplitPolicy()
- Deprecated. This feature has been replaced by the
InitialViewSettings class.
- Gets the viewer's split window policy. The policy can be one of two
values:
- SPLITPOLICY_USEDOCUMENTPAGEMODE - When a document is open, the viewer
will use the document page mode to decide how the split window should be displayed
and what tab (outlines, thumbnails) should be selected. When no page mode is defined
for the document, the viewer will select the thumnails in the split window.
- SPLITPOLICY_NEVER_VISIBLE - The split window is never visible for any document.
- Returns:
- The current split window policy.
setSplitPolicy
public void setSplitPolicy(int splitPolicy)
- Sets the viewer's split window policy. The policy can be one of two
values:
- SPLITPOLICY_USEDOCUMENTPAGEMODE - When a document is open, the viewer
will use the document page mode to decide how the split window should be displayed
and what tab (outlines, thumbnails) should be selected / visible. When no page mode is defined
for the document, the viewer will select the thumnails in the split window.
- SPLITPOLICY_NEVER_VISIBLE - The split window is never visible for any document.
- Parameters:
splitPolicy - The new split window policy.
showError
public void showError(String msg,
Throwable t)
- Convenience method to display an error message. This method will look at the exception and customize
the error message if the exception is a permissions exception (PDFPermissionException) or an out of memory
exception (OutOfMemoryError).
- Parameters:
msg - The message string to precede the exception error message.t - The exception that caused the error.
showMessage
public void showMessage(String msg)
- Convenience method to display a message using this PDFViewerBean as the message dialog's parent.
- Parameters:
msg - The message string to show to the user.
getPageByLocation
public int getPageByLocation(int x,
int y)
- Returns the index of a page given an x, y location on the document.
- Parameters:
x - The x coordinate of the point.y - The y coordinate of the point.
- Returns:
- The index of the page, -1 if the point does not fall on any page.
getZoomMode
public int getZoomMode()
- Get the current zoom mode.
- Returns:
- The current zoom mode, this can either be ZOOMMODE_NORMAL, ZOOMMODE_FITWIDTH, ZOOMMODE_FITPAGE.
setZoomMode
public void setZoomMode(int zoomMode)
- Sets the current zoom mode.
- Parameters:
zoomMode - The new zoom mode. This value has to be either ZOOMMODE_NORMAL, ZOOMMODE_FITWIDTH, or ZOOMMODE_FITPAGE.
If zoomMode is ZOOMMODE_FITWIDTH or ZOOMMODE_FITPAGE, the method will call setScale immediately to adjust the scale so that
the page fits in the display window optimally.
zoomToRect
public void zoomToRect(Rectangle2D zoomRect)
- Zooms the viewer to a particular rectangle on the document. The rectangle should be in "scroll pane" coordinates,
i.e. the entire document, including all pages, is considered one long canvas and the rectangle is the area into
this canvas that will be zoomed to.
- Parameters:
zoomRect - The rectangle to zoom into
getSelectedText
public TextSelection getSelectedText()
- Gets the current text selection (if any page has selected text) in the document.
- Returns:
- Object containing information about any text that is selected.
startMagnifyRect
public void startMagnifyRect()
- This method activates the magnification rectangle tool. This is equivalent to the user pressing
on the "magnify rectangle" button on the toolbar.
startLoupeTool
public void startLoupeTool()
- This method activates the loupe tool. This is equivalent to the user pressing
on the "loupe" button on the toolbar.
startTextSelection
public void startTextSelection()
- This methods activates the text selection tool. This is equivalent to the user pressing
the "text selection" button on the toolbar.
startTextSearch
public void startTextSearch()
- This method starts the text searching process. This is equivalent to the user pressing
the "Text Search" button on the toolbar.
startTextSearch
public void startTextSearch(String search)
- This method shows the text search dialog and tells it to search for a string.
closeTextSearch
public void closeTextSearch()
- Closes the text search box. This is equivalent to the user clicking on the Close button of the search dialog.
stopTextSelection
public void stopTextSelection()
- This method stops the text selection tool and activates the "hand" tool. If the bean is not in
text selection mode, the method does nothing.
setTextSelectionColors
public static void setTextSelectionColors(Color xorColor,
Color fgndColor)
- Set the colors used to highlight text on search results. when highlight text, the viewer draws
a rectangle around the text using XOR mode. XOR mode in Java requires two colors, one used for the
foreground and the secone one to use in the XOR operation. The sequence of calls are as follows:
Graphics2D.setXORMode (xorColor);
Graphics2D.setColor (fgndColor);
WARNING: These colors are held in static variables, they are used for all instances of PDFViewerBean.
- Parameters:
xorColor - The color used in the setXORMode call.fgndColor - The color used for the foreground in XOR mode.
getThumbnailPanel
public ThumbnailPanel getThumbnailPanel()
- Returns an interface to allow access to the thumbnail panel. The interface provides methods
to access the panel toolbar as well as to change the thumbnail sizes.
- Returns:
- Interface to the thumbnails panel
getBookmarkPanel
public BookmarkPanel getBookmarkPanel()
- Returns an interface to allow access to the bookmarks panel. The interface provides methods
to access the panel's toolbar as well as the bookmark tree.
- Returns:
- Interface to the bookmark panel
getAttachmentPanel
public AttachmentPanel getAttachmentPanel()
- Returns an interface to allow access to the attachment panel. The interface provides methods
to access the panel's toolbar as well as the attachment list.
- Returns:
- Interface to the attachment panel
getLayerPanel
public LayerPanel getLayerPanel()
- Returns an interface to allow access to the layer panel. The interface provides methods
to access the panel's toolbar as well as a list of layers.
- Returns:
- Interface to the layer panel
getSignaturePanel
public SignaturePanel getSignaturePanel()
- Returns an interface to allow access to the signature panel. The interface provides methods
to access the panel's toolbar as well as a list of signatures.
- Returns:
- Interface to the signature panel
getPageViewPanel
public PageViewPanel getPageViewPanel()
- Returns an interface to allow access to the page view panel. The interface provides methods
to access the PopupMenus which appear on the page.
- Returns:
- Interface to the page view panel panel
getCommentPanel
public CommentPanel getCommentPanel()
- Returns an interface to allow access to the comment panel. The interface provides methods
to access the panel's toolbar as well as a list of comments / annotations.
- Returns:
- Interface to the signature panel
setPageMode
public void setPageMode(int pageMode)
- Sets the page viewing mode in the viewer. The mode should be set using one of the
predefined values: PAGEMODE_CONTINUOUS, PAGEMODE_SINGLEPAGE, PAGEMODE_FACING and PAGEMODE_FACING_CONTINUOUS
- Parameters:
pageMode - The new page mode.
getPageMode
public int getPageMode()
- Returns the page viewing mode for viewer. The mode will be one of the
predefined values: PAGEMODE_CONTINUOUS, PAGEMODE_SINGLEPAGE, PAGEMODE_FACING and PAGEMODE_FACING_CONTINUOUS
getViewerContextMenu
public PageViewContextMenu getViewerContextMenu()
- Deprecated. Use getPageViewPanel.getPageContextMenu()
- Returns the ViewerContextMenu used for the content pane.
- Returns:
- the PageViewContextMenu
getSelectTextContextMenu
public TextSelectionContextMenu getSelectTextContextMenu()
- Deprecated. Use getPageViewPanel.getTextSelectionContextMenu()
- Returns the ContextMenu used for the content pane during text selection.
- Returns:
- the TextSelectionContextMenu
getToolbarButtonGroup
public ButtonGroup getToolbarButtonGroup()
- Returns a reference to the button group used to toggle some of the tools in the toolbar. This button group
can be used by the host application to add additional buttons to the toolbar that should be toggled along with
the standard buttons. The tool buttons that are part of the group are the magnification, hand, text select and
snapshop tools.
- Returns:
- A reference to the toolbar's toggle button group.
gotoPreviousView
public void gotoPreviousView()
- PDFViewer maintains a history of page views. Calling this method will
display the previous view from the history
gotoNextView
public void gotoNextView()
- PDFViewer maintains a history of page views. Calling this method will
display the previous view from the history
keyPressed
public void keyPressed(KeyEvent e)
- Handle key pressed events. PDFViewerBean handles page up and page down events to let the user
scroll up and down the document using these keys.
- Specified by:
keyPressed in interface KeyListener
keyReleased
public void keyReleased(KeyEvent e)
- Fullfill the KeyListener interfaces. PDFViewerBean does not do anything on key released events.
- Specified by:
keyReleased in interface KeyListener
keyTyped
public void keyTyped(KeyEvent e)
- Fullfill the KeyListener interfaces. PDFViewerBean does not do anything on key typed events.
- Specified by:
keyTyped in interface KeyListener
getCurrentLocation
public GotoPageAction getCurrentLocation()
- Returns the current location of the viewer as a GotoPageAction. The return value can then be used in
a call to PDFViewerBean.handleAction() to return to this location.
- Returns:
- The current location in the document, as a GotoPageAction object.
setFieldsHighlight
public void setFieldsHighlight(boolean highlight)
- Highlight any fields in the document. Highlighting fields will display a semi-transparent
blue rectangle over the field position so that the fields can be more easily seen by the user.
- Parameters:
highlight - Boolean flag indicating whether the fields should be highlighted.
isFieldsHighlight
public boolean isFieldsHighlight()
- Returns whether or not the fields should be highlighted.
- Returns:
- Flag indicating whether fields are highlighted.
getAnnotationManager
public AnnotationManager getAnnotationManager()
- Returns the object that manages annotation selection for this viewer.
- Returns:
- The annotation manager for this viewer.
getInitialViewSettings
public InitialViewSettings getInitialViewSettings()
- Returns the
InitialViewSettings object that specifies what
page mode, page layout, and magnification values should be used when opening
a document.
- Returns:
- The
InitialViewSettings for this PDFViewerBean.