Displaying a PDF Document in Acrobat Viewer
The Acrobat Viewer has a toolbar to navigate through the PDF
document with Next Page, Last Page, Previous Page, and First
Page buttons. A PDF document may be zoomed in or zoomed out with
the Zoom In or Zoom Out buttons. The Open and Open URL
buttons allow you to open a different PDF document, which replaces
the document currently displayed the Java AWT Component.
The Acrobat Viewer GUI functionality may also be accessed with
the com.adobe.acrobat package API from a Java
application. The different viewer commands are invoked with the
execMenuItem(java.lang.String viewerCommand) method of
the Viewer class. The viewer commands corresponding to
some of the Acrobat Viewer buttons are listed in the following
table.
| Acrobat Viewer Button |
Viewer Command |
| Next Page |
ViewerCommand.NextPage_K |
| Last Page |
ViewerCommand.LastPage_K |
| Previous Page |
ViewerCommand.PrevPage_K |
| First Page |
ViewerCommand.FirstPage_K |
| Zoom In, Zoom Out |
ViewerCommand.ZoomTo_K |
| Open |
ViewerCommand.Open_K |
| Find |
ViewerCommand.Find_K |
In the Viewer Component, you access the File, Edit, View,
Tools, and Help menus by right-clicking in the document. This
displays the pop-up menu seen in Figure 2.

Figure 2. PDF document menu
The File and Edit menu items may also be invoked with a viewer
command in a Java application. Some of the viewer commands
corresponding to the File and Edit menu items are listed in the
following table.
| Acrobat Viewer Menu Item |
Viewer Command |
| Close |
ViewerCommand.Close_K |
| Copy |
ViewerCommand.EditCopy_K |
| Select All |
ViewerCommand.EditSelectAll_K |
To display the PDF document at its actual size, select the
Actual Size button, as illustrated in Figure 3. The Actual Size
button may also be invoked with the viewer command
ViewerCommand.ActualSize_K.

Figure 3. Displaying document at actual size
To fit the PDF document in the AWT Component's
display space, select Fit Page, as illustrated in Figure 4. The Fit
Page button may also be invoked with the viewer command
ViewerCommand.FitPage_K.

Figure 4. Displaying document to fit page
To fit the PDF document to the width of the component, select
the Fit Width button, as illustrated in Figure 5. The Fit Width
button may also be invoked with the viewer command
ViewerCommand.FitWidth_K.

Figure 5. Displaying document to fit page width
Opening a Document
To open another PDF document, select the Open URL button, as shown
in Figure 6. The Open URL button may also be invoked with the
viewer command ViewerCommand.OpenURL_K.

Figure 6. Opening a document from a URL
In the Open URL frame, specify the URL of the PDF document, as
illustrated in Figure 7. The input field for the Open URL frame
does not accept a ftp-style URL with an escape
sequence, such as ftp://host/my%20file.pdf. On the other
hand, escapes are OK in http-style URLs.

Figure 7. Open URL
Bookmarking a Document
A PDF document page may be bookmarked in the Acrobat Viewer. The
Acrobat Viewer bookmark frame displays the bookmarks to a PDF
document with links to the different document pages. To bookmark a
page, select the Bookmark button, as illustrated in Figure 8.

Figure 8. Bookmarking a document
This adds a bookmark to the Acrobat Viewer, as shown in Figure 9.
You can obtain the root bookmark in the Acrobat Viewer frame from a
Java application with the getRootBookmark() method of
the Viewer class. The PDFBookmark class
represents a bookmark in a PDF document.
Viewer viewer;
PDFBookmark rootBookmark=viewer.getRootBookmark();
Obtain the different bookmarks in a PDF document that is displayed
in the Acrobat Viewer with the getBookmarks() method.
java.util.Vector pdfBookmarks=rootBookmark.getBookmarks();
The title of a bookmark can be obtained with the
getTitle() method.
PDFBookmark bookmark;
java.lang.String title=bookmark.getTitle();

Figure 9. PDF document with a bookmark
Selecting Text
In the Acrobat Viewer, text may be highlighted with the Select
Text button. Select the Select Text button and select the text to
be highlighted, as illustrated in Figure 10.

Figure 10. Selecting text
Conclusion
A Java application may need to display PDF documents. The Adobe
Acrobat Viewer for JavaBean API makes it feasible to display a PDF
document from a Java application.
Resources