Access PDF Viewer features from your code

Once you have integrated a PDF Viewer component, you may want to access its functions from your own java code. This section explains how to do this.

Sample Java code

Click here for example Java code.

 

How to interact with the Java PDF viewer

To interact with the Java PDF viewer is simple and it can all be handled through one method.

Object viewer.executeCommand(int, object[]) - Click here to view this method.

This method uses an int to specify what you wish to do and the object[] specifies input arguments where certain methods require it for full customisation, otherwise the method will use the standard jpedal code.

The returned Object returns anything that may be returned from the given command. Unless otherwise stated this value will be null. This will be useful if you wish to use your own popup windows for loading pdfs, printing etc.

The int values to specify a command to be used can be found in Commands.java.

 

Jump to Commands:

Open/Close a file

Transformation

Navigation

Display Options

Get Page Information

Saving/Printing

 

 

Open/Close a file

The following methods will accept an object[] input.

Commands.OPENFILE :: input = {“/PDFData/example.pdf”}
Input should be the full PDF filename expressed as a string

Commands.OPENFILE :: input = {new File(“/PDFData/example.pdf”)}
Input should be a PDF File object

Commands.OPENFILE :: input = {new FileInputStream(“/PDFData/example.pdf”)}
Input should be an InputStream containing data for a PDF file.

Commands.OPENFILE :: input = {new FileInputStream(“/PDFData/example.pdf”), “NamedDest”}
Input should be an InputStream containing data for a PDF file and a string for the name of the destination you wish to open the document at. This second variable can be used as a second variable for any of the above inputs.

Commands.OPENFILE :: input = {data, “/PDFData/example.pdf”}
Input should be a byte array of the pdf data you wish to load and the PDF filename expressed as a string

Commands.EXIT :: input = {null}
There is no required input for this function. Will close a Viewer. If you wish to just open another flle, use OpenFile options instead. If Viewer.exitOnClose set to false, JVM will be left running.

Commands.BOOKMARK:: input = {“exampleBookmark”}
Input should be the name of a bookmark expressed as a string. Will decode the bookmarked page. Current GUI must be active.

 

Transformation

Commands.ROTATION :: input = {“90″}
Input should be the PDF page rotation expressed as 0, 90, 180 or 270 expressed as a string

Commands.SCALING :: input = {“300″}
Input should be the PDF scaling value expressed as a string

Commands.SETPAGECOLOR :: input = {Color.BLUE.getRGB()}
Sets the background color of pages. The input is an integer representing a color

Commands.SETTEXTCOLOR :: input = {Color.BLUE.getRGB()}
Setsthe text color of pages. The input is an integer representing a color

Commands.REPLACETEXTCOLOR :: input = {Color.BLUE.getRGB()}
Replaces the text color of pages. The input is an integer representing a color

Commands.SETUNDRAWNPAGECOLOR :: input = {Color.GREEN.getRGB()}
Same as above except sets the color you wish the pages to be before they are rendered.

 

Navigation

Commands.FORWARDPAGE :: input = {“3″}
Input should be the amount of PDF pages to move by expressed as a string

Commands.FFORWARDPAGE :: input = {null}
This function does not require input. It will navigate forwards through the document 10 pages at a time.

Commands.BACKPAGE :: input = {“3″}
Input should be the amount of PDF pages to move by expressed as a string

Commands.FBACKPAGE :: input = {null}
This function does not require input. It will navigate backwards through the document 10 pages at a time.

Commands.FIRSTPAGE :: input = {null}
This function does not require an input. It will navigate to the first page of the document.

Commands.LASTPAGE :: input = {null}
This function does not require an input. It will navigate to the last page of the document.

Commands.GOTO :: input = {“3″}
Input should be the page number you want to navigate to expressed as a string.

Commands.OPENURL :: input = {“http://www.cs.bham.ac.uk/~axj/pub/papers/handy1.pdf”}
Input should be the full url of the PDF file location including “http://” at the start expressed as a string

Commands.SCROLL :: input = {new Rectangle(1,1,100,100), 1}
Input should be, as above, in the following order.
A Rectangle to scroll to on a PDF page.
An Integer value for the PDF page the area is on. If this value is less than 1, greater than the page count or the value is null then current PDF page is assumed.

Commands.AUTOSCROLL :: input = {null}
This function does not require an input. It Toggles autoscrolling (disables or enables it).

Commands.HIGHLIGHT :: input = {new Rectangle(1,1,100,100), 1, 1}
Input should be, as above, in the following order.
A Rectangle to scroll to on a PDF page.
A page number expressed as an integer that the area is on.
A boolean value of 1 or 0 which will determine whether or no there’s an area to select.

Commands.FIND :: input = {“example”, 0, true, false}
Input should be, as above, in the following order.
String representing the term or terms to be searched for.
Integer value representing a bitwise OR of the static values stored in the class SearchType representing search options.
Boolean value, if true, will treat search value as a list seperated by a space between each value else will treat the entire string as a single PDF search term.
Boolean value, if true, will only search the current page else the entire PDF document is searched.

Commands.PREVIOUSRESULT :: input = {null}
The input for this command should be a null array. This method will return one of four values.
null = Nothing of note to mention.
Commands.FIRST_DOCUMENT_SEARCH_RESULT_NOW_SHOWN = Integer of value 1 returned when we reach the first search value.
Commands.SEARCH_RETURNED_TO_START = Integer of value 2 returned when we loop between the start and end of the result list.
Commands.SEARCH_NOT_FOUND = Integer of value 3 returned if there are no search results found in this document.

Commands.NEXTRESULT :: input = {null}
The input for this command should be a null array. This method will return one of four values.
null = Nothing of note to mention.
Commands.FIRST_DOCUMENT_SEARCH_RESULT_NOW_SHOWN = Integer of value 1 returned when we reach the first search value.
Commands.SEARCH_RETURNED_TO_START = Integer of value 2 returned when we loop between the start and end of the result list.
Commands.SEARCH_NOT_FOUND = Integer of value 3 returned if there are no search results found in this document.

Commands.NEXTDOCUMENT :: input = {null}
The input for this comman should be null. This method will navigate and open the next PDF document.

Commands.PREVIOUSDOCUMENT:: input = {null}
The input for this comman should be null. This method will navigate and open the previous PDF document.

 

Display Options

Commands.SINGLE :: input = {null}
This function doesn’t require an input. Sets the visual navigation mode to single pages only.

Commands.CONTINUOUS :: input = {null}
This function doesn’t require an input. Sets the visual navigation mode to continuous pages.

Commands.CONTINUOUS_FACING :: input = {null}
This function doesn’t require an input. Sets the visual navigation mode to continuous_facing pages.

Commands.FACING :: input = {null}
This function doesn’t require an input. Sets the visual navigation mode to facing pages.

Commands.PAGEFLOW :: input = {null}
This function doesn’t require an input. Sets the visual navigation mode to pageflow.

Commands.FULLSCREEN :: input = {null}
This function doesn’t require an input. Determines if full-screen mode is supported, if it is then full-screen mode will be simulated.

 

Get Page Information

Commands.CURRENTPAGE :: input = null
There is no input required for this function. The returned object is an Integer representing the current page number.

Commands.PAGECOUNT :: input = null
There is no input required for this function. The returned object is an Integer for the value of the total number of pages in the currently loaded document.

Commands.PAGEGROUPING :: input = page number
Returns the PdfGrouping object for the page to access text.

Commands.GETOUTLINEPANEL :: input = null
There is no input required for this function. The returned object is the Viewer SwingOutline panel. It allows the plugins to display this externally (ie in a separate Eclipse view).

Commands.GETTHUMBNAILPANEL :: input = null
There is no input required for this function. The returned object is the thumbnails panel of object type GUIThumbnailPanel. It returns the thumbnails of the current SwingGUI.

 

Saving/Printing

Commands.SAVE :: input = {null}
This function takes a null input. Will save the curent file.

Commands.SAVEFORM :: input = {null}
This function takes a null input. Will save the form.

Commands.PRINT :: input = {null}
This function takes a null input. It will print the current file.