Class JSManager

  • public class JSManager
    extends JSCoreMethods

    Handles the Event - primarily JavaScript events - raised during the lifetime of the viewer. This class will raise the PDF lifetime events defined in the Acrobat JavaScript Scripting Reference, which may have PDFAction objects associated with them. These are unrelated to Swing events and to the DocumentPanelEvent, PagePanelEvent and similar.

    Since 2.11.18 is it possible to configure custom JavaScript that will run on certain events. This can be done by either calling the addCustomJavaScript(java.lang.String, method, or by setting a System property. As an example, here's how to run one custom scripts on App/Init and Doc/Open events:

      java -Dorg.faceless.pdf2.viewer2.JSManager.AppInit=myscripts/appinit.js \
           -Dorg.faceless.pdf2.viewer2.JSManager.DocOpen=myscripts/docopen.js \

    The value attribute is the path to a JavaScript file, the contents of which will be executed on the specified event

    With the exception of the above, we recommend developers and those working with the viewer steer well clear of calling into this class, as the API is subject to change without notice.

    • Method Detail

      • getViewer

        public final PDFViewer getViewer()
        Return the PDFViewer this JSManager is a part of
      • getDocumentPanel

        public final DocumentPanel getDocumentPanel​(PDF pdf)
        Return the DocumentPanel that contains the specified PDF
      • getImplementationDescription

        public String getImplementationDescription()
        Return a description of the JavaScript implementation in use
      • getComponent

        public final Object getComponent​(PDFAnnotation annot)
        Return the JComponent matchin the specified PDFAnnotation
      • getLastMousePosition

        public Point2D getLastMousePosition​(PDF pdf)
        Get the point in PDF space where the last mouse event (MouseEnter, MouseExit, MouseUp, MouseDown) occurred
      • appBeep

        public void appBeep()
        An implementation of the App.beep JavaScript method
      • consoleShow

        public void consoleShow()
        An implementation of the JavaScript method
      • consoleHide

        public void consoleHide()
        An implementation of the Console.hide JavaScript method
      • consolePrintln

        public void consolePrintln​(String message)
        An implementation of the Console.println JavaScript method
      • consoleClear

        public void consoleClear()
        An implementation of the Console.clear JavaScript method
      • appAlert

        public int appAlert​(String message,
                            int nIcon,
                            int nType,
                            String cTitle,
                            Object oDoc,
                            Object oCheckbox)
        An implementation of the App.alert JavaScript method
      • appResponse

        public String appResponse​(String message,
                                  String cTitle,
                                  String cDefault,
                                  boolean bPassword,
                                  String cLabel)
        An implementation of the App.response JavaScript method
      • runEventAppInit

        public void runEventAppInit()
        Raise the App/Init JavaScript method
      • runEventBatchExec

        public JSEvent runEventBatchExec​(DocumentPanel panel,
                                         PDF pdf,
                                         String javascript)
        Raise the Batch/Exec JavaScript method
      • runEventBookmarkMouseUp

        public JSEvent runEventBookmarkMouseUp​(DocumentPanel panel,
                                               PDFBookmark bookmark)
        Raise the Bookmark/MouseUp JavaScript method
      • runEventConsoleExec

        public JSEvent runEventConsoleExec​(DocumentPanel panel,
                                           String javascript)
        Raise the Console/Exec JavaScript method
      • runEventDocDidPrint

        public JSEvent runEventDocDidPrint​(DocumentPanel panel)
        Raise the Doc/DidPrint JavaScript method
      • runEventDocDidSave

        public JSEvent runEventDocDidSave​(DocumentPanel panel)
        Raise the Doc/DidSave JavaScript method
      • runEventDocOpen

        public JSEvent runEventDocOpen​(DocumentPanel panel,
                                       String targetName)
        Raise the Doc/Open JavaScript method
      • runEventDocWillClose

        public JSEvent runEventDocWillClose​(DocumentPanel panel)
        Raise the Doc/WillClose JavaScript method
      • runEventDocWillPrint

        public JSEvent runEventDocWillPrint​(DocumentPanel panel)
        Raise the Doc/WillPrint JavaScript method
      • runEventDocWillSave

        public JSEvent runEventDocWillSave​(DocumentPanel panel)
        Raise the Doc/WillSave JavaScript method
      • runEventExternalExec

        public JSEvent runEventExternalExec​(DocumentPanel panel,
                                            String javascript)
        Raise the External/Exec JavaScript method
      • runEventFieldBlur

        public JSEvent runEventFieldBlur​(DocumentPanel panel,
                                         WidgetAnnotation annot,
                                         boolean shift,
                                         boolean modifier)
        Raise the Field/Blur JavaScript method
      • runEventFieldFocus

        public JSEvent runEventFieldFocus​(DocumentPanel panel,
                                          WidgetAnnotation annot,
                                          boolean shift,
                                          boolean modifier)
        Raise the Field/Focus JavaScript method
      • runEventFieldFormat

        public JSEvent runEventFieldFormat​(DocumentPanel panel,
                                           WidgetAnnotation annot,
                                           int commitKey,
                                           boolean willCommit)
        Raise the Field/Format JavaScript method
      • runEventFieldKeystroke

        public JSEvent runEventFieldKeystroke​(DocumentPanel panel,
                                              WidgetAnnotation annot,
                                              int commitKey,
                                              String change,
                                              String changeEx,
                                              boolean fieldFull,
                                              boolean keyDown,
                                              boolean modifier,
                                              int selStart,
                                              int selEnd,
                                              boolean shift,
                                              String value,
                                              boolean willCommit)
        Raise the Field/Keystroke JavaScript method
      • runEventFieldValidate

        public JSEvent runEventFieldValidate​(DocumentPanel panel,
                                             WidgetAnnotation annot,
                                             String value,
                                             boolean shift,
                                             boolean modifier,
                                             String change,
                                             String changeEx,
                                             boolean keyDown)
        Raise the Field/Validate JavaScript method
      • runEventLinkMouseUp

        public JSEvent runEventLinkMouseUp​(DocumentPanel panel,
                                           AnnotationLink annot)
        Raise the Link/Mouse Up JavaScript method
      • runEventPageOpen

        public JSEvent runEventPageOpen​(DocumentPanel panel,
                                        PDFPage page)
        Raise the Page/Open JavaScript method
      • runEventPageClose

        public JSEvent runEventPageClose​(DocumentPanel panel,
                                         PDFPage page)
        Raise the Page/Close JavaScript method
      • addCustomJavaScript

        public void addCustomJavaScript​(String event,
                                        URL url)
                                 throws IOException
        Add some custom JavaScript to the viewer.
        event - the event type, eg "App/Init" or "Doc/Open"
        url - the URL to load the JavaScript from
      • addCustomJavaScript

        public void addCustomJavaScript​(String event,
                                        String script)
        Add some custom JavaScript to the viewer.
        event - the event type, eg "App/Init" or "Doc/Open"
        script - the JavaScript to execute on that event
      • setAppRuntimeHighlight

        public void setAppRuntimeHighlight​(boolean highlight)
        Sets whether to highlight form fields displayed in the viewer using the color from getAppRuntimeHighlightColor(). The default value can be set by the property, which can be set to "true" to enable this by default.
        highlight - true to highlight form fields
      • setAppRuntimeHighlightColor

        public void setAppRuntimeHighlightColor​(Color c)
        Sets the color to highlight form fields if setAppRuntimeHighlight(boolean) returns true. The default value can be set by the property, which may be an HTML-style color (eg "#FF0000").
        c - the highlight color
      • setAppFocusRect

        public void setAppFocusRect​(boolean value)
        Sets whether to mark form fields with focus with a dotted rectangle. The default value can be set by the property, which can be set to "false" to disable this by default.
        value - true to highlight form fields