Access PDF Viewer features from your code

download-jpedal-library-trial

[Click to edit the title]

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.

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.FORWARDPAGE :: input = {"3"}
Input should be the amount of PDF pages to move by expressed as a string

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

Commands.ROTATION :: input = {"90"}
Input should be the PDF page rotation expressed as 0, 90, 180 or 270 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.SCALING :: input = {"300"}
Input should be the PDF scaling value 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.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.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. (Used in the Eclipse PDF plugin).

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 displa this externally (ie in a separate Eclipse view).

Commands.SETPAGECOLOR :: input = {Color.BLUE.getRGB()}
Sets the background 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.