|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
by Deepak Vohra | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Property | Description | Type |
Default_Page_Layout |
The page layout of the PDF document. Values that may specified
are: SinglePage, OneColumn, TwoColumn (same as
TwoColumnRight), TwoColumnLeft, and TwoColumnRight. |
Static |
Default_Zoom_Type |
The zoom type of the PDF document. Values that may be
specified are: FixedZoom, FitPage, FitVisible, FitWidth,
FitVisibleWidth, FitHeight, and FitVisibleHeight. |
Static |
Default_Magnification |
The percent of magnification, with values in the range of 25-800. | Static |
Max_Magnification |
The maximum magnification, with values in the range of 25-800. | Static |
Page_Units |
Page units may be set to Points, Millimeters, or Inches. |
Dynamic |
Display_Large |
Boolean value. Set to display large images in a PDF document. | Dynamic |
Server_Printers |
String value specifying the relative path to get a list of printers. | Dynamic |
Server_Print |
String value specifying the relative path to print a document. | Dynamic |
To set the page layout to SinglePage, the zoom type
to FitPage, and the magnification to 100 percent, you just make a
series of calls to setProperty():
viewer.setProperty("Default_Page_Layout",
"SinglePage");
viewer.setProperty("Default_Zoom_Type",
"FitPage");
viewer.setProperty("Default_Magnification",
"100");
The number of pages in the PDF document and the current page are
obtained with the getPageCount() and
getCurrentPage() methods. As an example, print out the
number of pages in the example document and the current page
displayed.
System.out.println("Page Count: "+viewer.getPageCount());
System.out.println("Current Page: "+viewer.getCurrentPage());
Page 0 corresponds to the first page in the document.
You can set the zoom level of the current page with the
zoomTo() method. Set the zoom magnification to 100 percent by
specifying 1.0 as a double in the zoomTo() method.
viewer.zoomTo(1.0);
Create the layout of the viewer components and activate the viewer as follows:
viewer.activate();
Next, set the frame size in which the viewer is to be added, and display the frame.
frame.setSize(400, 500);
frame.pack();
frame.show();
You'll find the example application PDFViewer.java in the Resources section. Run the Java application in a command-line window. The number of pages for the example PDF document is 3 and the current page is 0, the index of the first page of the PDF document. The example PDF document gets displayed in the Acrobat Viewer. As the zoom level is set to 1.0 in the Java application, the PDF document is displayed with 1.0 magnification. Figure 1 illustrates the PDF document in Acrobat Viewer.

Figure 1. PDF Document in Acrobat Viewer
The Acrobat Viewer provides some viewer commands to edit the
document and to modify the view characteristics of the document.
The viewer commands are specified in the ViewerCommand
interface, which is implemented by the Viewer class.
To run a viewer command, invoke the
execMenuItem(java.lang.String viewerCommand) method of
the Viewer class. For example, to run the
ZoomTo_K command:
Viewer viewer=new Viewer();
viewer.execMenuItem(ViewerCommand.ZoomTo_K);
Some of the commonly used viewer commands are listed in the following table:
| Viewer Command | Description |
FitPage_K |
Displays document to fit page. |
FitHeight_K |
Displays document to fit height. |
FitWidth_K |
Displays document to fit width. |
OpenURL_K |
Displays the URL selection dialog. |
Open_K |
Displays the file selection dialog. |
PageOnly_K |
Displays the page without the bookmarks. |
Print_K |
Displays the Print Document dialog. |
PrintSetup_K |
Displays the Print Document dialog. |
ShowBookmarks_K |
Displays the bookmarks. |
TwoColumn_K |
Displays the document in two-column mode. |
ZoomTo_K |
Displays the Zoom To dialog. |
The Acrobat Viewer may be displayed with some of the toolbar buttons removed. For example, you can remove the Open and Open URL buttons in the Acrobat Viewer with:
String[] dis = {ViewerCommand.Open_K, ViewerCommand.OpenURL_K};
Viewer viewer = new Viewer(dis);
Pages: 1, 2 |
View all java.net Articles.
|
|