View Source

\\
\\
In previous examples, the ICEpdf library has been used as a standalone renderer for capturing page content and extracting document information. The ICEpdf library can also be used to create a full- feature PDF Viewer component which can be inserted into any Java application. For more information
on the viewer component features, see {color:#004ca5}*Reference*{color} {color:#004ca5}*Implementations*{color} {color:#004ca5}*and*{color} {color:#004ca5}*Examples{*}{color}, p. 28.
\\
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.
\\
{color:#004ca5}*Figure 1 ICEpdf MVC Implementation*{color}

*SwingController*
*SwingView* *Factory*

!worddav7b184e558eb0b98a937715bb9c8a04c9.png|height=279,width=438!
*ViewModel*
*Document*
{color:#004ca5}*Creating*{color} {color:#004ca5}*a*{color} {color:#004ca5}*Viewer*{color} {color:#004ca5}*Component*{color}
\\
The *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();
\\
// 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 );
\\
\\
{color:#b90000}*Note:*{color} The SwingViewBuilder class provides numerous methods that enable developers to quickly
create custom viewer user interfaces (UIs) by including only those UI controls that are required, customizing existing UI controls, etc. Refer to
*org.icepdf.core.ri.common.SwingViewBuilder* in the JavaDoc API documentation and
{color:#004ca5}*Customizing the SwingViewBuilder{*}{color}, p. 23 for more information.
\\
\\
See {color:#004ca5}*ICEpdf*{color} {color:#004ca5}*Viewer*{color} {color:#004ca5}*Application{*}{color}, p. 28 for a complete example.
\\
\\
\\