Jun 062012

I recently started using the excellent ICEpdf library to display PDFs in a Java application. And as invariably happens with most libraries, I wanted to do something that is just not documented anywhere yet. 🙂 Or at least anywhere that I can find…

But lets first look at the available documentation:

I am using the Viewer, creating the panel as per the first link above. But I want to configure which buttons are visible on the toolbar at run time, according to user settings persisted in a database. This rules out the option of using the config file route. And hence I needed to find a way to change the configuration programmatically.

So I debugged into the source code, and I found out that there is indeed an easy way. 🙂

SwingController controller = new SwingController();
PropertiesManager propertiesManager = new PropertiesManager(
        System.getProperties(), new Properties(), 
        PropertiesManager.PROPERTY_SHOW_UTILITY_SAVE, false);
SwingViewBuilder factory = 
        new SwingViewBuilder(controller, propertiesManager);
JPanel viewerComponentPanel = factory.buildViewerPanel();