The PDF Viewer application is a reference implementation (RI) application, meaning that all source code used to implement the application is available to developers to modify as required. The PDF Viewer RI uses the Model-View-Controller (MVC) design pattern for communication between the user, the GUI and the PDF document data. The PDF Viewer's data model is implemented by the ViewModel class. The view, which presents the user interface, is implemented using standard Java Swing components and is constructed by the SwingViewBuilder class. The controller, which interacts between the user, view and data model is represented by the SwingController class. This relationship can be seen in Figure 1. The combination of the MVC design and the SwingViewBuilder and SwingController classes provides a very powerful and easily adaptable approach to PDF Viewer GUI development. Developers using ICEpdf can readily customize the Viewer user-interface with a very shallow learning curve and minimal coding effort. Figure 1 - ICEpdf MVC Implementation Creating a Viewer ComponentThe org.icepdf.core.ri.common.SwingController class provides convenience methods for the most common UI actions, such as rotating the document, setting the zoom level, etc. The org.icepdf.core.ri.common.SwingViewBuilder class is responsible for creating the PDF Viewer component panel populated with Swing components configured to work with the SwingController. When using the SwingViewBuilder and SwingController classes, it is usually not necessary to use the Document object directly. The SwingController class does this for us. The following code snippet illustrates how to build a PDF Viewer component: String filePath = "somefilepath/myfile.pdf"; // build a controller SwingController controller = new SwingController(); // Build a SwingViewFactory configured with the controller SwingViewBuilder factory = new SwingViewBuilder(controller); // Use the factory to build a JPanel that is pre-configured //with a complete, active Viewer UI. JPanel viewerComponentPanel = factory.buildViewerPanel(); // add copy keyboard command ComponentKeyBinding.install(controller, viewerComponentPanel); // add interactive mouse link annotation support via callback controller.getDocumentViewController().setAnnotationCallback( new org.icepdf.ri.common.MyAnnotationCallback( controller.getDocumentViewController())); // Create a JFrame to display the panel in JFrame window = new JFrame("Using the Viewer Component"); window.getContentPane().add(viewerComponentPanel); window.pack(); window.setVisible(true); // Open a PDF document to view controller.openDocument(filePath);
|
Using the PDF Viewer Component
© Copyright 2017 ICEsoft Technologies Canada Corp.