Link

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.

The PDF Viewer has two methods to allow you to access the Viewers functionality or retrieve information from the Viewer.

Retrieving Information from the Viewer

Retrieving information about the current page/display can be retrieved using the method
Object Viewer.getViewerValue(ViewerValues) - View this method. Using ViewerValues as input you can return the following values.

  • ViewerValues.CURRENTPAGE - Returned object is an Integer of the current page.
  • ViewerValues.PAGECOUNT - Returned object is an Integer of the total page count.
  • ViewerValues.PDFNAME - Returned object is a String representing the PDF filename.
  • ViewerValues.SCALE - Returned object is a Float representing the scaling as a multiplier (where 1 is 100%).
  • ViewerValues.ROTATION - Returned object is an Integer of the current pages rotation in the display.
  • ViewerValues.PAGELAYOUT Returned object is an Integer representing the page layout using the values below.
    • Display.SINGLE_PAGE = 1
    • Display.CONTINUOUS = 2
    • Display.CONTINUOUS_FACING = 3
    • Display.FACING = 4
    • Display.PAGEFLOW = 5
    • Display.PORTFOLIO_DETAIL = 6
    • Display.PORTFOLIO_TILE = 7

Accessing Viewer Functionality

Viewer functionality can be executed using the following method.
Object Viewer.executeCommand(ViewerCommands command, Object… args) - View this method.

This method uses the ViewerCommands enum to specify the functionality to be executed and an 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.

List of JPedal Functions

  1. File Open/Close
    1. ViewerCommands.OPENFILE
    2. ViewerCommands.OPENURL
    3. ViewerCommands.PREVIOUSDOCUMENT
    4. ViewerCommands.NEXTDOCUMENT
    5. ViewerCommands.EXIT
  2. Page Navigation
    1. ViewerCommands.FORWARDPAGE
    2. ViewerCommands.FFORWARDPAGE
    3. ViewerCommands.BACKPAGE
    4. ViewerCommands.FBACKPAGE
    5. ViewerCommands.FIRSTPAGE
    6. ViewerCommands.LASTPAGE
    7. ViewerCommands.GOTO
    8. ViewerCommands.BOOKMARK
    9. ViewerCommands.SCROLL
  3. Display Controls
    1. ViewerCommands.ROTATION
    2. ViewerCommands.ROTATELEFT
    3. ViewerCommands.ROTATERIGHT
    4. ViewerCommands.SCALING
    5. ViewerCommands.ZOOMIN
    6. ViewerCommands.ZOOMOUT
    7. ViewerCommands.SINGLE
    8. ViewerCommands.CONTINUOUS
    9. ViewerCommands.CONTINUOUS_FACING
    10. ViewerCommands.FACING
    11. ViewerCommands.PAGEFLOW
    12. ViewerCommands.PORTFOLIO_DETAIL
    13. ViewerCommands.PORTFOLIO_TILES
    14. ViewerCommands.FULLSCREEN
    15. ViewerCommands.OPENINSYSTEMDEFAULT
  4. Page Render Settings
    1. ViewerCommands.SEPARATECOVER
    2. ViewerCommands.SETENHANCEFRACTIONALLINES
    3. ViewerCommands.SETHIDELINEWEIGHTS
    4. ViewerCommands.SETHIGHLIGHTFORMFIELDS
  5. Interactive Features
    1. ViewerCommands.SAVE
    2. ViewerCommands.PRINT
    3. ViewerCommands.MOUSEMODE
    4. ViewerCommands.PANMODE
    5. ViewerCommands.TEXTSELECT
    6. ViewerCommands.SELECTALL
    7. ViewerCommands.DESELECTALL
    8. ViewerCommands.FIND
    9. ViewerCommands.PREVIOUSRESULT
    10. ViewerCommands.NEXTRESULT
    11. ViewerCommands.UPDATEGUILAYOUT
    12. ViewerCommands.VISITWEBSITE
    13. ViewerCommands.HIGHLIGHT
  6. Dialogs
    1. ViewerCommands.ABOUT
    2. ViewerCommands.BITMAP
    3. ViewerCommands.IMAGES
    4. ViewerCommands.TEXT
    5. ViewerCommands.DOCINFO
    6. ViewerCommands.TIP
    7. ViewerCommands.PREFERENCES
    8. ViewerCommands.EXTRACTTEXT
    9. ViewerCommands.EXTRACTIMAGE
    10. ViewerCommands.SNAPSHOT
  7. Customization
    1. ViewerCommands.SETDISPLAYBACKGROUND
    2. ViewerCommands.SETPAGECOLOR
    3. ViewerCommands.SETTEXTCOLOR
    4. ViewerCommands.CHANGELINEART
    5. ViewerCommands.SETREPLACEMENTCOLORTHRESHOLD
    6. ViewerCommands.SETUNDRAWNPAGECOLOR
    7. ViewerCommands.AUTOSCROLL
    8. ViewerCommands.HIDEVERSIONNUMBER
    9. ViewerCommands.SHOWVERSIONNUMBER

File Open/Close


ViewerCommands.OPENFILE

Open a specified PDF or open a dialog to pick a PDF.

Input Values
Each call to this method can accept one of the following types of value.

  • A String representing the absolute filename for the PDF.
  • A File object for the PDF.
  • An InputStream containing the PDF files content.
  • A byte[] containing the contents of a PDF followed by a String presenting the PDF filename.
  • No input to instead open a dialog to select a PDF.

Output Values None


ViewerCommands.OPENURL

Open a PDF from a given URL or open a dialog to enter a URL.

Input Values
Each call to this method can accept one of the following types of value.

  • A String representing the URL pointing to a PDF.
  • No input to instead open a dialog to enter a URL.

Output Values None


ViewerCommands.PREVIOUSDOCUMENT

Open the last document opened. This command works through the recent files list which can be found in the File Menu.

Input Values
None

Output Values None


ViewerCommands.NEXTDOCUMENT

Open the next document to be opened. This can be used after ViewerCommands.PREVIOUSDOCUMENT to return to the document viewed before.

Input Values
None

Output Values None


ViewerCommands.EXIT

Close the Viewer. The Viewer has a flag Viewer.exitOnClose. If this is true the Viewer will call System.exit(1) which will shutdown the JVM.

Input Values
None

Output Values None



ViewerCommands.FORWARDPAGE

Navigate forward a given number of pages.

Input Values Each call to this method can accept one of the following types of value.

  • A String specifying the number of pages to move forward (increases current page by the given amount).
  • None to move to the next page (increases current page by one).

Output Values None


ViewerCommands.FFORWARDPAGE

Navigate forward by 10 pages.

Input Values
None

Output Values None


ViewerCommands.BACKPAGE

Navigate backward a given number of pages.

Input Values
Each call to this method can accept one of the following types of value.

  • A String specifying the number of pages to move backward (decreases current page by the given amount).
  • None to move to the next page (decreases current page by one).

Output Values None


ViewerCommands.FBACKPAGE

Navigate backward by 10 pages.

Input Values
None

Output Values None


ViewerCommands.FIRSTPAGE

Navigate to the first page of the document.

Input Values
None

Output Values None


ViewerCommands.LASTPAGE

Navigate to the final page of the document.

Input Values
None

Output Values None


ViewerCommands.GOTO

Navigate to the specified page of the document.

Input Values
A String representing the number of the page to navigate to.

Output Values None


ViewerCommands.BOOKMARK

Navigate to the specified Bookmark in the PDF.

Input Values
A String representing the name of a bookmark within the PDF.

Output Values None


ViewerCommands.SCROLL

Navigate to show the specified portion of a page. This does not affect the scaling or rotation of the page.

Input Values
This command takes 2 input.

  1. A Rectangle Object describing an area on a page to scroll to.
  2. An Integer specifying the page containing the area to scroll to.

Output Values None


Display Controls


ViewerCommands.ROTATION

Set the pages rotation to the given amount.

Input Values
A String value of either “0”, “90”, “180”, “270”.

Output Values None


ViewerCommands.ROTATELEFT

Rotates the page 90 degrees counter-clockwise from its current rotation.

Input Values
None

Output Values None


ViewerCommands.ROTATERIGHT

Rotates the page 90 degrees clockwise from its current rotation.

Input Values
None

Output Values None


ViewerCommands.SCALING

Set the pages scaling to the given amount.

Input Values
A ViewerScaling value of the scaling required. Possible values include:

  • ViewerScaling.FIT_WIDTH
  • ViewerScaling.FIT_HEIGHT
  • ViewerScaling.FIT_PAGE
  • ViewerScaling.PERCENT_50
  • ViewerScaling.PERCENT_100
  • ViewerScaling.PERCENT_150
  • ViewerScaling.PERCENT_200
  • ViewerScaling.PERCENT_250
  • ViewerScaling.CUSTOM (followed by a String value representing the scaling percentage)

Examples:

Viewer.executeCommand(ViewerCommands.SCALING, new Object[] {ViewerScaling.CUSTOM, "80"}); // Scales the page to 80%

Viewer.executeCommand(ViewerCommands.SCALING, ViewerScaling.FIT_WIDTH); // Scales the page to fit the width of the Viewer

Output Values None


ViewerCommands.ZOOMIN

Increases the pages scaling to the next largest value in the scaling combo box

Input Values
None

Output Values None


ViewerCommands.ZOOMOUT

Decreases the pages scaling to the next lowest value in the scaling combo box

Input Values
None

Output Values None


ViewerCommands.SINGLE

Sets the display mode to Single Page mode. This mode displays a single page in the Viewer at a time.

Input Values
None

Output Values None


ViewerCommands.CONTINUOUS

Sets the display mode to Continuous Page mode. This mode displays all pages as a continuous column of pages, loaded and rendered as needed.

Input Values
None

Output Values None


ViewerCommands.CONTINUOUS_FACING

Sets the display mode to Continuous Facing Page mode. This mode displays all pages as a continuous column of 2 pages, loaded and rendered as needed. Odd number pages are on the right, even pages on the left.

Input Values
None

Output Values None


ViewerCommands.FACING

Sets the display mode to Facing Page mode. This mode displays 2 pages in a row, loaded and rendered as needed. Odd number pages are on the right, even pages on the left. If there are only 2 pages they are displayed with odd pages on the left, keeping them beside each other.

Input Values
None

Output Values None


ViewerCommands.PAGEFLOW

Sets the display mode to Pageflow Page mode. This mode displays a single page in the center of the view with all other pages rotated along the Y axis. This display mode required JavaFX to function.

Input Values
None

Output Values None


ViewerCommands.PORTFOLIO_DETAIL

Sets the display mode to Detail mode which will display a table of details for each item in the portfolio. This function only works when a Portfolio PDF is open.

Input Values
None

Output Values None


ViewerCommands.PORTFOLIO_TILES

Sets the display mode to Tiles mode which will display a series of tiles for each item in the portfolio. This function only works when a Portfolio PDF is open.

Input Values
None

Output Values None


ViewerCommands.FULLSCREEN

Sets the Viewer to be displayed in Fullscreen mode, which hides the standard frame and has the Viewer take up the whole screen.
When on it puts odd page ont he right, otherwise they are put on the left.

Input Values
None

Output Values None


ViewerCommands.OPENINSYSTEMDEFAULT

Open the current file (or specified file) in the current systems default application.

Input Values Each call to this method can accept one of the following types of value.

  • A String representing the absolute filename for the PDF.
  • None, which will instead open the file currently open in the Viewer.

Output Values None


Page Render Settings


ViewerCommands.SEPARATECOVER

Toggle the separate cover option used by Facing and Continuous Facing modes that displays the first page by itself or not.

Input Values
None

Output Values None


ViewerCommands.SETENHANCEFRACTIONALLINES

Set if lines that would render at a stroke width of less than 1 should instead be rendered with a width of 1.
This will prevent lines becoming so small that they are no longer visible.

Input Values
A Boolean value to turn this option on (true) or off (false)

Output Values None


ViewerCommands.SETHIDELINEWEIGHTS

Set if stroked shapes should ignore the contents’ width, instead rendering all shapes with a stroke of 1.

Input Values
A Boolean value to turn this option on (true) or off (false)

Output Values None


ViewerCommands.SETHIGHLIGHTFORMFIELDS

Set if editable form fields should be highlighted to make it easier to locate them on the page.

Input Values
A Boolean value to turn this option on (true) or off (false)

Output Values None


Interactive Features


ViewerCommands.SAVE

Save the PDF with any changes to form content. This will open a dialog to specify a location to save the file.

Input Values
None

Output Values None


ViewerCommands.PRINT

Opens a dialog to specify print options and print the file.

Input Values
None

Output Values None


ViewerCommands.MOUSEMODE

Swaps between the two mouse modes Text Select (allows mouse to select text) and Pan Mode (allows mouse to be used to move the page view). If the current mode is Text Select, this function changes it to Pan Mode. If the current mode is Pan Mode, this function changes it to Text Select.

Input Values
None

Output Values None


ViewerCommands.PANMODE

Set the current mouse mode to Pan Mode which allows you to drag the mouse in order to change the viewed area of the page.

Input Values
None

Output Values None


ViewerCommands.TEXTSELECT

Set the current mouse mode to Text Select which allows you to click and drag over text in order to select it.

Input Values
None

Output Values None


ViewerCommands.SELECTALL

All text on the current page is highlighted using the text selection functionality

Input Values
None

Output Values None


ViewerCommands.DESELECTALL

All highlighted text on the current page has the highlights and selection removed.

Input Values
None

Output Values None


ViewerCommands.FIND

Allows you to search for a particular string of text on the page. Upon completion the first result found will be highlighted.

Input Values
This command accepts 4 input values.

  1. A String value for the term to search.
  2. An Integer representing SearchType values, using a bitwise OR to combine multiple options.
  3. A Boolean to control if the string should be treated as multiple space separated search terms (when true), or not.
  4. A Boolean to search just the current page (when true), or the whole document.

Output Values None


ViewerCommands.PREVIOUSRESULT

Clears the current highlighted result and changes the display to the previous result which is then highlighted.

Input Values
None

Output Values An Integer is returned with one of 3 possible values.

  1. (Commands.FIRST_DOCUMENT_SEARCH_RESULT_NOW_SHOWN == 1) Returned when this action reaches the first search result from the search.
  2. (Commands.SEARCH_RETURNED_TO_START == 2) Returned when this action loops back to the first search result from the search.
  3. (Commands.SEARCH_NOT_FOUND == 3) Returned if there are no search results found in this document.

ViewerCommands.NEXTRESULT

Clears the current highlighted result and changes the display to the next result which is then highlighted.

Input Values
None

Output Values An Integer is returned with one of 3 possible values.

  1. (Commands.FIRST_DOCUMENT_SEARCH_RESULT_NOW_SHOWN == 1) Returned when this action reaches the first search result from the search.
  2. (Commands.SEARCH_RETURNED_TO_START == 2) Returned when this action loops back to the first search result from the search.
  3. (Commands.SEARCH_NOT_FOUND == 3) Returned if there are no search results found in this document.

ViewerCommands.UPDATEGUILAYOUT

Allows you to alter the visibility of GUI elements within the Viewer, whilst teh Viewer is open and visible.

Input Values
This command accepts 2 input values. A String for the element name. A Boolean for the new visibility of the element (true for visible, false for invisible).

Output Values None


ViewerCommands.VISITWEBSITE

Opens the system default web browser and displays the IDRSolutions home page.

Input Values
None

Output Values None


ViewerCommands.HIGHLIGHT

Specify an area of section of text to be highlighted.

Input Values
This command accepts 3 input values.

  1. An Integer[][] containing 4 value Integer arrays that define areas ont he page.
  2. A page to apply the highlight to.
  3. A Boolean to specify if the areas should be treated as text selection (false) or the exact area for a highlight (true).

Output Values None


Dialogs


ViewerCommands.ABOUT

Open the Viewers About dialog that details when JPedal is, displays the version of Jpedal and Java, and provides a link to the JPedal webpage.

Input Values
None

Output Values None


ViewerCommands.BITMAP

Open a dialog to allow you to extract all pages as individual images in different formats.

Input Values
None

Output Values None


ViewerCommands.IMAGES

Open a dialog to allow you to extract all image content from the PDF pages.

Input Values
None

Output Values None


ViewerCommands.TEXT

Open a dialog to allow you to extract all text content from the PDF pages.

Input Values
None

Output Values None


ViewerCommands.DOCINFO

Open a dialog to display a variety of information regarding the current PDF including page size and crop values, fonts, forms, and more.

Input Values
None

Output Values None


ViewerCommands.TIP

Open a dialog to display a random tip for using the Viewer. This can be done on start up without this function be setting the properties file key “displaytipsonstartup” to true.

Input Values
None

Output Values None


ViewerCommands.PREFERENCES

Open a dialog to display Viewer Properties loaded from the current properties file and allows users to alter these values and save the changes.

Input Values
None

Output Values None


ViewerCommands.EXTRACTTEXT

Open a dialog to display Text extraction preview and options for the currently highlighted text.

Input Values
None

Output Values None


ViewerCommands.EXTRACTIMAGE

Open a dialog to allow you to save the currently highlighted image content on the page (this content is highlighted by clicking on the image in text select mode).

Input Values
None

Output Values None


ViewerCommands.SNAPSHOT

Once triggered the user can select a region on the page, after which a dialog opens to allow the user to cancel, save the selected area as an image, or copy the area as an image to the system clipboard.

Input Values
None

Output Values None


Customization


ViewerCommands.SETDISPLAYBACKGROUND

Set the color of the display behind the PDF pages.

Input Values
An Integer representing the Color value. This can be made using Color.getRGB().

Output Values None


ViewerCommands.SETPAGECOLOR

Set the background color of the PDF pages.

Input Values
An Integer representing the Color value. This can be made using Color.getRGB().

Output Values None


ViewerCommands.SETTEXTCOLOR

Set the color of the Text on PDF pages.

Input Values
An Integer representing the Color value. This can be made using Color.getRGB().

Output Values None


ViewerCommands.CHANGELINEART

Specify if Shapes should also have its color changes as well as text.

Input Values
A Boolean to specify if shapes should have the color changed to match the text color.

Output Values None


ViewerCommands.SETREPLACEMENTCOLORTHRESHOLD

Set a threshold under which text will have its color replaced. This threshold is a value of which all RGB values must be below in order to be replaced.

Input Values
An Integer value to be used to determine which text has its color replaced.

Output Values None


ViewerCommands.SETUNDRAWNPAGECOLOR

Set the color of the PDF pages displayed before the content is drawn.

Input Values
An Integer representing the Color value. This can be made using Color.getRGB().

Output Values None


ViewerCommands.AUTOSCROLL

Allows you to toggle if the Viewer will scroll the page whilst selecting text. By default this option is true but can be modified in the properties file.

Input Values
None

Output Values None


ViewerCommands.HIDEVERSIONNUMBER

Allow the user to remove the JPedal version number from the default JFrame title bar.

Input Values
None

Output Values None


ViewerCommands.SHOWVERSIONNUMBER

Allow the user to include the JPedal version number from the default JFrame title bar.

Input Values
None

Output Values None



Start Your Free Trial


Customer Downloads

Select Download