-
Notifications
You must be signed in to change notification settings - Fork 21
Implementing an AnnotationCallback
ICEpdf can optionally be configured to support interacting with link annotations. The Viewer RI and Pilot RI, by default, come configured with their own implementations of the org.icepdf.core.AnnotationCallback
. They differ only by how they handle external URI Actions. The Viewer RI will load an external URI with the Operating System's default web browser.
ICEpdf only supports annotations via the mouse pointer; there is no keyboard support at this time. When the mouse is moved over a portion of a PDF document which is marked as an annotation, the mouse cursor will change into a hand with a pointing finger. When a user clicks on the annotation, ICEpdf will draw any effect specified by the selected annotation, but it will not execute the annotation action; it instead passes the selected annotation to the AnnotationCallback. It is up to the AnnotationCallback implementation to process the annotation's actions.
A default implementation of an AnnotationCallback can be found in org.icepdf.core.ri.common.MyAnnotationCallback
.
The following code snippet shows how to configure the SwingController
with an AnnotationCallback
that would allow the user to interact with annotations in a PDF document.
// build a component controller
SwingController controller = new SwingController();
SwingViewBuilder factory = new SwingViewBuilder(controller);
JPanel viewerComponentPanel = factory.buildViewerPanel();
// add interactive mouse link annotation support via callback
controller.getDocumentViewController().setAnnotationCallback(
new org.icepdf.ri.common.MyAnnotationCallback(
controller.getDocumentViewController()));
JFrame applicationFrame = new JFrame();
applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
applicationFrame.getContentPane().add(viewerComponentPanel);
// Now that the GUI is all in place, we can try openning a PDF
controller.openDocument(filePath);