Class JSManager
- java.lang.Object
-
- JSCoreMethods
-
- org.faceless.pdf2.viewer2.JSManager
-
public class JSManager extends JSCoreMethodsHandles 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
PDFActionobjects associated with them. These are unrelated to Swing events and to theDocumentPanelEvent,PagePanelEventand 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, java.net.URL)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 \ org.faceless.pdf2.viewer2.PDFViewerThe
valueattribute is the path to a JavaScript file, the contents of which will be executed on the specified eventWith 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.
- Since:
- 2.9
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCustomJavaScript(String event, String script)Add some custom JavaScript to the viewer.voidaddCustomJavaScript(String event, URL url)Add some custom JavaScript to the viewer.intappAlert(String message, int nIcon, int nType, String cTitle, Object oDoc, Object oCheckbox)An implementation of theApp.alertJavaScript methodvoidappBeep()An implementation of theApp.beepJavaScript methodvoidappOpenDoc(String cPath, PDF pdf, String cFS, Boolean bHidden, Boolean bUseConv, String cDest)An implementation of theApp.openDocJavaScript methodStringappResponse(String message, String cTitle, String cDefault, Boolean bPassword, String cLabel)An implementation of theApp.responseJavaScript methodvoidconsoleClear()An implementation of theConsole.clearJavaScript methodvoidconsoleHide()An implementation of theConsole.hideJavaScript methodvoidconsolePrintln(String message)An implementation of theConsole.printlnJavaScript methodvoidconsoleShow()An implementation of theConsole.showJavaScript methodStringdocExportAsXFDFStr(PDF pdf, Boolean bAllFields, Boolean bNoPassword, FormElement[] fields, Boolean bAnnotations, String cHRef)booleangetAppFocusRect()Return the value set bysetAppFocusRect(boolean)booleangetAppRuntimeHighlight()Return the value set bysetAppRuntimeHighlight(boolean)ColorgetAppRuntimeHighlightColor()Return the value set bysetAppRuntimeHighlightColor(java.awt.Color)ObjectgetComponent(PDFAnnotation annot)Return the JComponent matchin the specified PDFAnnotationStringgetCustomJavaScript(String type, String name)Return any Custom JavaScript to be run when the specified event is received.DocumentPanelgetDocumentPanel(PDF pdf)Return the DocumentPanel that contains the specified PDFStringgetImplementationDescription()Return a description of the JavaScript implementation in usePoint2DgetLastMousePosition(PDF pdf)Get the point in PDF space where the last mouse event (MouseEnter, MouseExit, MouseUp, MouseDown) occurredPDFViewergetViewer()Return the PDFViewer this JSManager is a part ofvoidrunEventAppInit()Raise theApp/InitJavaScript methodJSEventrunEventBatchExec(DocumentPanel panel, PDF pdf, String javascript)Raise theBatch/ExecJavaScript methodJSEventrunEventBookmarkMouseUp(DocumentPanel panel, PDFBookmark bookmark)Raise theBookmark/MouseUpJavaScript methodJSEventrunEventConsoleExec(DocumentPanel panel, String javascript)Raise theConsole/ExecJavaScript methodJSEventrunEventDocDidPrint(DocumentPanel panel)Raise theDoc/DidPrintJavaScript methodJSEventrunEventDocDidSave(DocumentPanel panel)Raise theDoc/DidSaveJavaScript methodJSEventrunEventDocOpen(DocumentPanel panel, String targetName)Raise theDoc/OpenJavaScript methodJSEventrunEventDocWillClose(DocumentPanel panel)Raise theDoc/WillCloseJavaScript methodJSEventrunEventDocWillPrint(DocumentPanel panel)Raise theDoc/WillPrintJavaScript methodJSEventrunEventDocWillSave(DocumentPanel panel)Raise theDoc/WillSaveJavaScript methodJSEventrunEventExternalExec(DocumentPanel panel, String javascript)Raise theExternal/ExecJavaScript methodJSEventrunEventFieldBlur(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)Raise theField/BlurJavaScript methodJSEventrunEventFieldCalculate(DocumentPanel panel, WidgetAnnotation target, WidgetAnnotation source)Raise theField/CalculateJavaScript methodJSEventrunEventFieldFocus(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)Raise theField/FocusJavaScript methodJSEventrunEventFieldFormat(DocumentPanel panel, WidgetAnnotation annot, int commitKey, boolean willCommit)Raise theField/FormatJavaScript methodJSEventrunEventFieldKeystroke(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 theField/KeystrokeJavaScript methodJSEventrunEventFieldMouseDown(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)Raise theField/Mouse DownJavaScript methodJSEventrunEventFieldMouseEnter(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)Raise theField/Mouse EnterJavaScript methodJSEventrunEventFieldMouseExit(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)Raise theField/Mouse ExitJavaScript methodJSEventrunEventFieldMouseUp(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)Raise theField/Mouse UpJavaScript methodJSEventrunEventFieldValidate(DocumentPanel panel, WidgetAnnotation annot, String value, boolean shift, boolean modifier, String change, String changeEx, boolean keyDown)Raise theField/ValidateJavaScript methodJSEventrunEventLinkMouseUp(DocumentPanel panel, AnnotationLink annot)Raise theLink/Mouse UpJavaScript methodJSEventrunEventPageClose(DocumentPanel panel, PDFPage page)Raise thePage/CloseJavaScript methodJSEventrunEventPageOpen(DocumentPanel panel, PDFPage page)Raise thePage/OpenJavaScript methodvoidsetAppFocusRect(boolean value)Sets whether to mark form fields with focus with a dotted rectangle.voidsetAppRuntimeHighlight(boolean highlight)Sets whether to highlight form fields displayed in the viewer using the color fromgetAppRuntimeHighlightColor().voidsetAppRuntimeHighlightColor(Color c)Sets the color to highlight form fields ifsetAppRuntimeHighlight(boolean)returns true.
-
-
-
Method Detail
-
getViewer
public final PDFViewer getViewer()
Return the PDFViewer this JSManager is a part of- Since:
- 2.11
-
getDocumentPanel
public final DocumentPanel getDocumentPanel(PDF pdf)
Return the DocumentPanel that contains the specified PDF- Since:
- 2.11
-
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 theApp.beepJavaScript method
-
consoleShow
public void consoleShow()
An implementation of theConsole.showJavaScript method
-
consoleHide
public void consoleHide()
An implementation of theConsole.hideJavaScript method
-
consolePrintln
public void consolePrintln(String message)
An implementation of theConsole.printlnJavaScript method
-
consoleClear
public void consoleClear()
An implementation of theConsole.clearJavaScript method
-
appAlert
public int appAlert(String message, int nIcon, int nType, String cTitle, Object oDoc, Object oCheckbox)
An implementation of theApp.alertJavaScript method
-
appOpenDoc
public void appOpenDoc(String cPath, PDF pdf, String cFS, Boolean bHidden, Boolean bUseConv, String cDest)
An implementation of theApp.openDocJavaScript method
-
appResponse
public String appResponse(String message, String cTitle, String cDefault, Boolean bPassword, String cLabel)
An implementation of theApp.responseJavaScript method
-
docExportAsXFDFStr
public String docExportAsXFDFStr(PDF pdf, Boolean bAllFields, Boolean bNoPassword, FormElement[] fields, Boolean bAnnotations, String cHRef)
-
runEventAppInit
public void runEventAppInit()
Raise theApp/InitJavaScript method
-
runEventBatchExec
public JSEvent runEventBatchExec(DocumentPanel panel, PDF pdf, String javascript)
Raise theBatch/ExecJavaScript method
-
runEventBookmarkMouseUp
public JSEvent runEventBookmarkMouseUp(DocumentPanel panel, PDFBookmark bookmark)
Raise theBookmark/MouseUpJavaScript method
-
runEventConsoleExec
public JSEvent runEventConsoleExec(DocumentPanel panel, String javascript)
Raise theConsole/ExecJavaScript method
-
runEventDocDidPrint
public JSEvent runEventDocDidPrint(DocumentPanel panel)
Raise theDoc/DidPrintJavaScript method
-
runEventDocDidSave
public JSEvent runEventDocDidSave(DocumentPanel panel)
Raise theDoc/DidSaveJavaScript method
-
runEventDocOpen
public JSEvent runEventDocOpen(DocumentPanel panel, String targetName)
Raise theDoc/OpenJavaScript method
-
runEventDocWillClose
public JSEvent runEventDocWillClose(DocumentPanel panel)
Raise theDoc/WillCloseJavaScript method
-
runEventDocWillPrint
public JSEvent runEventDocWillPrint(DocumentPanel panel)
Raise theDoc/WillPrintJavaScript method
-
runEventDocWillSave
public JSEvent runEventDocWillSave(DocumentPanel panel)
Raise theDoc/WillSaveJavaScript method
-
runEventExternalExec
public JSEvent runEventExternalExec(DocumentPanel panel, String javascript)
Raise theExternal/ExecJavaScript method
-
runEventFieldBlur
public JSEvent runEventFieldBlur(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/BlurJavaScript method
-
runEventFieldCalculate
public JSEvent runEventFieldCalculate(DocumentPanel panel, WidgetAnnotation target, WidgetAnnotation source)
Raise theField/CalculateJavaScript method
-
runEventFieldFocus
public JSEvent runEventFieldFocus(DocumentPanel panel, WidgetAnnotation annot, boolean shift, boolean modifier)
Raise theField/FocusJavaScript method
-
runEventFieldFormat
public JSEvent runEventFieldFormat(DocumentPanel panel, WidgetAnnotation annot, int commitKey, boolean willCommit)
Raise theField/FormatJavaScript 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 theField/KeystrokeJavaScript method
-
runEventFieldMouseDown
public JSEvent runEventFieldMouseDown(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse DownJavaScript method
-
runEventFieldMouseEnter
public JSEvent runEventFieldMouseEnter(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse EnterJavaScript method
-
runEventFieldMouseExit
public JSEvent runEventFieldMouseExit(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse ExitJavaScript method
-
runEventFieldMouseUp
public JSEvent runEventFieldMouseUp(DocumentPanel panel, WidgetAnnotation annot, MouseEvent mevent)
Raise theField/Mouse UpJavaScript method
-
runEventFieldValidate
public JSEvent runEventFieldValidate(DocumentPanel panel, WidgetAnnotation annot, String value, boolean shift, boolean modifier, String change, String changeEx, boolean keyDown)
Raise theField/ValidateJavaScript method
-
runEventLinkMouseUp
public JSEvent runEventLinkMouseUp(DocumentPanel panel, AnnotationLink annot)
Raise theLink/Mouse UpJavaScript method
-
runEventPageOpen
public JSEvent runEventPageOpen(DocumentPanel panel, PDFPage page)
Raise thePage/OpenJavaScript method
-
runEventPageClose
public JSEvent runEventPageClose(DocumentPanel panel, PDFPage page)
Raise thePage/CloseJavaScript method
-
getCustomJavaScript
public String getCustomJavaScript(String type, String name)
Return any Custom JavaScript to be run when the specified event is received. This method checks each of theFeaturesin the PDFViewer for custom JavaScript, and returns the concatenation of all of them.
-
addCustomJavaScript
public void addCustomJavaScript(String event, URL url) throws IOException
Add some custom JavaScript to the viewer.- Parameters:
event- the event type, eg "App/Init" or "Doc/Open"url- the URL to load the JavaScript from- Throws:
IOException- Since:
- 2.11.18
-
addCustomJavaScript
public void addCustomJavaScript(String event, String script)
Add some custom JavaScript to the viewer.- Parameters:
event- the event type, eg "App/Init" or "Doc/Open"script- the JavaScript to execute on that event- Since:
- 2.11.18
-
setAppRuntimeHighlight
public void setAppRuntimeHighlight(boolean highlight)
Sets whether to highlight form fields displayed in the viewer using the color fromgetAppRuntimeHighlightColor(). The default value can be set by theJavaScript.app.runtimeHighlightproperty, which can be set to "true" to enable this by default.- Parameters:
highlight- true to highlight form fields- Since:
- 2.11.12
-
getAppRuntimeHighlight
public boolean getAppRuntimeHighlight()
Return the value set bysetAppRuntimeHighlight(boolean)- Since:
- 2.11.12
-
setAppRuntimeHighlightColor
public void setAppRuntimeHighlightColor(Color c)
Sets the color to highlight form fields ifsetAppRuntimeHighlight(boolean)returns true. The default value can be set by theJavaScript.app.runtimeHighlightColorproperty, which may be an HTML-style color (eg "#FF0000").- Parameters:
c- the highlight color- Since:
- 2.11.12
-
getAppRuntimeHighlightColor
public Color getAppRuntimeHighlightColor()
Return the value set bysetAppRuntimeHighlightColor(java.awt.Color)- Since:
- 2.11.12
-
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 theJavaScript.app.focusRectproperty, which can be set to "false" to disable this by default.- Parameters:
value- true to highlight form fields- Since:
- 2.11.12
-
getAppFocusRect
public boolean getAppFocusRect()
Return the value set bysetAppFocusRect(boolean)- Since:
- 2.11.12
-
-