com.adobe.acrobat
Class Viewer

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--com.adobe.acrobat.Viewer

public class Viewer
extends java.applet.Applet
implements RenderingObserver, ViewerCommand

Viewer is the primary exported class for the Acrobat Viewer. It contains interfaces for running the Viewer as an Application, an Applet, or a Bean.

Only the classes and methods at this level of the class hierarchy (that is: com.adobe.acrobat.*) are guaranteed to be present without obfuscating name changes.

Here is a code fragment that creates a viewer and adds it to a frame.

   Frame frame = new Frame("Test Viewer");
   frame.setLayout(new BorderLayout());
   Viewer viewer = new Viewer();
   frame.add(viewer, BorderLayout.CENTER);
   viewer.activate();
   frame.setSize(400, 500);
   frame.show();
 

Copyright (c) 1999, Adobe Systems Inc., All Rights Reserved.

Version:
1.1
See Also:
Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

 

Constructor Summary
Viewer()
          Construct a Viewer object.
Viewer(boolean useCache)
          Construct a Viewer object, and optionally disables the use of the Font cache.
Viewer(java.lang.String[] disallowedCommands)
          Construct a Viewer object, where the given commands are removed from the UI of the viewer (from toolbar, menubar, and popup menus).

 

Method Summary
 void activate()
          Creates Layout of the Viewer component and prepares it for display.
 void activateWithoutBars()
          Creates Layout of the Viewer component without a toolbar and without a status bar, and prepares it for display.
 void deactivate()
          The deactivate method should be called after the Viewer is no longer needed.
 void destroy()
          The destroy method overrides the Applet destroy method and is called by the browser before the applet is destroyed.
static boolean enabledDebug()
          Internal method to check for debugging enabled.
 void execMenuItem(java.lang.String viewerCommand)
          Executes a Viewer command.
 java.lang.String getAppletInfo()
          Returns a localized string containing version and copyright information about the this Applet.
 java.net.URL getCodeBase()
          Gets the base URL.
 com.adobe.acrobat.gui.AcroViewContext getContext()
          This is an internal method.
 int getCurrentPage()
          Get the page number of the currently displayed page.
 java.lang.String getDocumentURL()
          Returns the full URL of the document.
 java.awt.Frame getFrame()
          This is an internal method.
 int getPageCount()
          Get the total number of pages in the current document.
 java.lang.String[][] getParameterInfo()
          Returns information about the parameters than are understood by this applet.
 java.util.Properties getProperties()
          get all Viewer properties
 java.lang.String getProperty(java.lang.String key)
          get a Viewer property
 PDFBookmark getRootBookmark()
          Gets the root bookmark associated with this document.
 java.lang.String getTextForPage(int pageNumber)
          Get all of the text on a page.
 void gotoNamedDest(java.lang.String dest)
          go to a PDF named destination
 void init()
          Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
static void main(java.lang.String[] args)
          Application startup code.
 Viewer openNewWindow()
          Opens a new window on the current document.
 void printAll()
          Print all pages of the document.
 void printPages(int start, int end)
          Print a selected page range from the document
static void registerViewerWindow(java.awt.Frame f)
          Register an active window with the Viewer.
 void renderingDone()
          Completion callback method that is called when a page is fully rendered.
 void renderPage(int pageNumber)
          Completely render the page with the given page number.
 void setDocumentByteArray(byte[] bytes)
          Open a document from an array of bytes in memory.
 void setDocumentByteArraySource(ByteArraySource bas)
          Open a document from a ByteArraySource.
 void setDocumentInputStream(java.io.InputStream stm)
          Open a document from an InputStream.
 void setDocumentURL(java.lang.String docURL)
          Open a document from a URL.
static void setEnableDebug(boolean debug)
          turn on certain debugging functions in the Viewer.
 void setProperty(java.lang.String key, java.lang.String value)
          Set a Viewer property.
 void setRenderingObserver(RenderingObserver ro)
          Sets a rendering observer whose renderingDone method gets called after a page has been completely rendered with the renderPage method.
static void unregisterViewerWindow(java.awt.Frame f)
          Unregister an active window with the Viewer.
 void zoomTo(double zoomLevel)
          Zoom the current page to the the given zoom level in percentages.

 

Methods inherited from class java.applet.Applet
getAppletContext, getAudioClip, getAudioClip, 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, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree

 

Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, 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, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

Viewer

public Viewer()
       throws java.lang.Exception
Construct a Viewer object. This Viewer needs to be activated before you can show it.
Throws:
java.lang.Exception - if a Viewer cannot be constructed.
See Also:
activate(), activateWithoutBars()

Viewer

public Viewer(boolean useCache)
       throws java.lang.Exception
Construct a Viewer object, and optionally disables the use of the Font cache. This Viewer needs to be activated before you can show it.
Parameters:
useCache - false to disable use of the Font cache (desirable for devices that have no file system).
Throws:
java.lang.Exception - if a Viewer cannot be constructed.
See Also:
activate(), activateWithoutBars()

Viewer

public Viewer(java.lang.String[] disallowedCommands)
       throws java.lang.Exception
Construct a Viewer object, where the given commands are removed from the UI of the viewer (from toolbar, menubar, and popup menus). For example, here is how you can create a viewer with the Open_K and OpenURL_K commands removed:
 
 String[] dis = {ViewerCommand.Open_K, ViewerCommand.OpenURL_K};
 Viewer viewer = new Viewer(dis);
 
 
Parameters:
disallowedCommands - an array of viewer command names.
Throws:
java.lang.Exception - if a Viewer cannot be constructed.
See Also:
activate(), activateWithoutBars(), ViewerCommand
Method Detail

getRootBookmark

public PDFBookmark getRootBookmark()
                            throws java.lang.Exception
Gets the root bookmark associated with this document. The Root bookmark is typically not displayed (because it has no title or associated action). Its descendants are the initial set of bookmarks that are displayed and which could be manipulated.
Returns:
the root of the PDFBookmark tree
Throws:
java.lang.Exception - if the root bookmark cannot be determined.

getCodeBase

public java.net.URL getCodeBase()
Gets the base URL. This is the URL of the Applet itself. If invoked as a Bean, then this is the file URL of the current working directory.
Returns:
the URL of this Applet or Bean
Overrides:
getCodeBase in class java.applet.Applet

registerViewerWindow

public static void registerViewerWindow(java.awt.Frame f)
Register an active window with the Viewer. The Viewer exits when the total number of registered active windows goes to zero.

This is an internal method. Do not call it directly.


unregisterViewerWindow

public static void unregisterViewerWindow(java.awt.Frame f)
Unregister an active window with the Viewer. The Viewer exits when the total number of registered active windows goes to zero.

This is an internal method. Do not call it directly.


destroy

public void destroy()
The destroy method overrides the Applet destroy method and is called by the browser before the applet is destroyed. This method will save your preferences file.

The default implementation simply calls deactivate

Overrides:
destroy in class java.applet.Applet
See Also:
deactivate()

deactivate

public void deactivate()
The deactivate method should be called after the Viewer is no longer needed. Part of this method includes saving your preferences file.

activate

public void activate()
              throws java.lang.Exception
Creates Layout of the Viewer component and prepares it for display. This method should be called after the constructor and before the parent panel is shown.
Throws:
java.lang.Exception - throws an exception if a viewer cannot be initialized.
See Also:
activateWithoutBars()

activateWithoutBars

public void activateWithoutBars()
                         throws java.lang.Exception
Creates Layout of the Viewer component without a toolbar and without a status bar, and prepares it for display. This method should be called after the constructor and before the parent panel is shown.
Throws:
java.lang.Exception - if a viewer cannot be initialized.
See Also:
activate()

getContext

public com.adobe.acrobat.gui.AcroViewContext getContext()
This is an internal method. Do not call it directly.

main

public static void main(java.lang.String[] args)
Application startup code.
Parameters:
-d - means start with debug support (requires Debug classes)
-u - url of a pdf file to open
-r - full-path of a directory to ready resources from (if omitted the Resources directory relative to the location of the Viewer class is used).

setEnableDebug

public static void setEnableDebug(boolean debug)
turn on certain debugging functions in the Viewer. Applications use the -d (debug) flag Applets use the DEBUG property
Parameters:
debug - true to turn on debug functions

enabledDebug

public static boolean enabledDebug()
Internal method to check for debugging enabled.
Returns:
true if debugging is enabled.

init

public void init()
Called by the browser or applet viewer to inform this applet that it has been loaded into the system.
Overrides:
init in class java.applet.Applet

getFrame

public java.awt.Frame getFrame()
This is an internal method. Do not call it directly.

execMenuItem

public void execMenuItem(java.lang.String viewerCommand)
                  throws java.lang.Exception
Executes a Viewer command. The command is passed by name.
Parameters:
viewerCommand - a valid ViewerCommand name.
Throws:
java.lang.Exception - throws an exception if the viewerCommand is not a recognized command.
See Also:
ViewerCommand

openNewWindow

public Viewer openNewWindow()
                     throws java.lang.Exception
Opens a new window on the current document.
Returns:
a Viewer/code> object.
Throws:
java.lang.Exception - if a new window cannot be created.

zoomTo

public void zoomTo(double zoomLevel)
            throws java.lang.Exception
Zoom the current page to the the given zoom level in percentages.
Parameters:
zoomLevel - the factor to zoom to, e.g., to zoom to 200%, pass the value of 2.0, or to set the zoom to 50%, pass the value of 0.5.
Throws:
java.lang.Exception - if zooming cannot be done.

getParameterInfo

public java.lang.String[][] getParameterInfo()
Returns information about the parameters than are understood by this applet.
Returns:
the parameters supported by this applet.
Overrides:
getParameterInfo in class java.applet.Applet

getAppletInfo

public java.lang.String getAppletInfo()
Returns a localized string containing version and copyright information about the this Applet.
Returns:
a localized string describing version and copyright information.
Overrides:
getAppletInfo in class java.applet.Applet

setDocumentURL

public void setDocumentURL(java.lang.String docURL)
                    throws java.lang.Exception
Open a document from a URL.
Parameters:
docURL - a URL, which may be relative to the document base.
Throws:
java.lang.Exception - if the URL cannot be opened.

getDocumentURL

public java.lang.String getDocumentURL()
                                throws java.lang.Exception
Returns the full URL of the document. If the document is not sourced from a URL, returns "".
Returns:
fully qualified URL
Throws:
java.lang.Exception - if document URL cannot be obtained.

setDocumentByteArray

public void setDocumentByteArray(byte[] bytes)
                          throws java.lang.Exception
Open a document from an array of bytes in memory.
Parameters:
bytes - a complete PDF file. The byte array should be no longer than the file, so the EOF can be found.
Throws:
java.lang.Exception - if document source cannot be set

setDocumentByteArraySource

public void setDocumentByteArraySource(ByteArraySource bas)
                                throws java.lang.Exception
Open a document from a ByteArraySource.
Parameters:
bas - the ByteArraySource from which to get the ByteArray whose contents will be displayed.
Throws:
java.lang.Exception - if document source cannot be set

setDocumentInputStream

public void setDocumentInputStream(java.io.InputStream stm)
                            throws java.lang.Exception
Open a document from an InputStream.
Parameters:
stm - a java.io.InputStream
Throws:
java.lang.Exception - if document source cannot be set

renderPage

public void renderPage(int pageNumber)
                throws java.lang.Exception
Completely render the page with the given page number.
Parameters:
pageNumber - Must be a number between 0 and getPageCount() - 1, inclusive.
Throws:
java.lang.Exception - if the page cannot be rendered, for example: invalid page number.

Here is an example using this method to automatically render all pages in the current opened document.

 
  for (int i = 1; i 
 
See Also:
getPageCount()

renderingDone

public void renderingDone()
Completion callback method that is called when a page is fully rendered. You should not explicitly use this method in your code.
Specified by:
renderingDone in interface RenderingObserver

setRenderingObserver

public void setRenderingObserver(RenderingObserver ro)
Sets a rendering observer whose renderingDone method gets called after a page has been completely rendered with the renderPage method.
Parameters:
ro - The RenderingObserver, registers a observer whose renderingDone method gets called. To unregister, call this method and pass null.
See Also:
renderPage(int)

getCurrentPage

public int getCurrentPage()
                   throws java.lang.Exception
Get the page number of the currently displayed page. Pages are numbered from 0 The page layout mode must be SinglePage
Returns:
current page number.
Throws:
java.lang.Exception - if current page cannot be obtained.

getPageCount

public int getPageCount()
                 throws java.lang.Exception
Get the total number of pages in the current document.
Returns:
number of pages.
Throws:
java.lang.Exception - if document page count cannot be obtained.

gotoNamedDest

public void gotoNamedDest(java.lang.String dest)
                   throws java.lang.Exception
go to a PDF named destination
Parameters:
dest - a String with the name of the destination
Throws:
java.lang.Exception - if an error occurs

getTextForPage

public java.lang.String getTextForPage(int pageNumber)
                                throws java.lang.Exception
Get all of the text on a page. You must have permission to copy Text.
Parameters:
pageNumber - Must be a number between 0 and getPageCount() - 1, inclusive.
Returns:
a String containing all the text in Unicode
Throws:
java.lang.Exception - if document page count cannot be obtained.

printAll

public void printAll()
              throws java.lang.Exception
Print all pages of the document.
Throws:
java.lang.Exception - if printing fails.
See Also:
printPages(int, int)

printPages

public void printPages(int start,
                       int end)
                throws java.lang.Exception
Print a selected page range from the document
Parameters:
start - the starting page number (pages are numbered from 0)
end - the ending page number
Throws:
java.lang.Exception - if printing fails.

setProperty

public void setProperty(java.lang.String key,
                        java.lang.String value)
                 throws java.lang.Exception
Set a Viewer property. Property list is kept in a static field, and is applied to all instances of the Applet/Bean. The properties that may be set are:

The following properties can be set before the viewer is displayed.

Default_Page_Layout
"SinglePage", "OneColumn", "TwoColumn" (same as "TwoColumnRight"), "TwoColumnLeft", "TwoColumnRight"
 
Default_Zoom_Type
"FixedZoom", "FitPage", "FitVisible, "FitWidth", "FitVisibleWidth", "FitHeight", "FitVisibleHeight""
Default_Magnification
Integer in the range 25-800. If you set the Default_Magnification to other than 100 [percent] the Default_Zoom_Type will be set to FixedZoom
Max_Magnification
Integer in the range 25-800.

The following properties may be changed at any time

Substitution_Fonts
"Sans", "Serif", "Sans&Serif"
Page_Units
"Points", "Millimeters", "Inches"
Display_Large
boolean: Display large images
Greek_Text
boolean: Turn text Greeking on or off
Greek_Text_Limit
Integer > 0

These are printing defaults. They are global to all instances of the applet

Print_Method_Known
boolean: If set, try to run with no dialogs
Use_Print_Server
boolean: If set, use Iron City
Shrink_To_Fit
boolean: only honored by Iron City
Fax_Fine_Mode
boolean: Fax default used by Iron City
Server_Home
String: path to Iron City print server
Server_Printers
String: relative path to get list of printers
Server_Print
String: relative path to print a document
Last_Printer
String: name of last selected printer
Parameters:
key - property key string
value - property value string
Throws:
java.lang.Exception - if property cannot be set

getProperty

public java.lang.String getProperty(java.lang.String key)
                             throws java.lang.Exception
get a Viewer property
Parameters:
key - name of the property
Returns:
property value
Throws:
java.lang.Exception - if an error occurs
See Also:
setProperty(java.lang.String, java.lang.String)

getProperties

public java.util.Properties getProperties()
                                   throws java.lang.Exception
get all Viewer properties
Returns:
all properties as a Properties table
Throws:
java.lang.Exception - if an error occurs