Disabling toolbar from icePDF viewer

2.8k views Asked by At

I am trying a sample with icePDF . Everything is working fine but i need to disable the toolbar which appears at the top. i tried few things but its not working. Can some body please help me out with it. Below is my code.

//package XML.test;

package applet;

import java.util.ResourceBundle;

import javax.swing.JFrame;

import javax.swing.JPanel;

import org.icepdf.ri.common.ComponentKeyBinding;
import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.util.PropertiesManager;
import org.icepdf.core.pobjects.fonts.*;
import org.icepdf.core.views.DocumentViewController;
import org.icepdf.core.*;

public class ViewerComponentExample 
{

    static void buildFrame(String filepath)
    {
        System.getProperties().put("org.icepdf.core.scaleImages", "false"); 
        System.getProperties().put("org.icepdf.core.imageReference","smoothScaled");
        System.getProperties().put("org.icepdf.core.target.dither", "VALUE_DITHER_DISABLE"); 
        System.getProperties().put("org.icepdf.core.target.fractionalmetrics", "VALUE_FRACTIONALMETRICS_OFF"); 
        System.getProperties().put("org.icepdf.core.target.interpolation", "VALUE_INTERPOLATION_NEAREST_ NEIGHBOR"); 
        System.getProperties().put("org.icepdf.core.screen.interpolation", "VALUE_INTERPOLATION_NEAREST_NEIGHBOR"); 
        System.getProperties().put("org.icepdf.core.awtFontLoading","true");
        SwingController controller = new SwingController();

        PropertiesManager properties = new PropertiesManager(System.getProperties(), ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
        properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_ANNOTATION, Boolean.FALSE);
        properties.setBoolean(PropertiesManager.PROPERTY_SHOW_TOOLBAR_FIT, Boolean.FALSE); 
        // Build a SwingViewFactory configured with the controller

        SwingViewBuilder factory = new SwingViewBuilder(controller);

        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()));

        // Use the factory to build a JPanel that is pre-configured
        //with a complete, active Viewer UI.
        // Create a JFrame to display the panel in
        JFrame window = new JFrame("Metrics Wizard Help");
        window.getContentPane().add(viewerComponentPanel);
        window.pack();
        window.setVisible(true);
        controller.setPageFitMode(DocumentViewController.PAGE_FIT_WINDOW_WIDTH, false);
         controller.openDocument(filepath);

    }

    public static void main(String args[]) 
    {
         String filepath = "C:/Users/vishalt/Workspaces/Eclipse 4.2 Java/htmltopdf/src/XML/output/SCB_TEST.pdf";
        buildFrame(filepath);  
    }


}
2

There are 2 answers

0
John Wayne On
private SwingController controller;
controller = new SwingController();
SwingViewBuilder viewBuilder = new SwingViewBuilder(controller, properties);
JPanel panel = viewBuilder.buildViewerPanel();
controller.setToolBarVisible(false);

You have to set the toolbar invisible because icePdf looks in the PDF-document for the property and overwrites your setting with default when there is no document opened!

0
Adam On

There are two ways to this.

1) Follow this example to set all the toolbars to false. http://www.icesoft.org/JForum/posts/list/17673.page#sthash.48ICrL2A.dpbs

2) You can modify or remove the toolbar by editing the source code for SwingViewBuilder.

Here is a link to the code: http://sventon.icesoft.org/svn/repos/repo/show//icepdf/trunk/icepdf/viewer/src/org/icepdf/ri/common/SwingViewBuilder.java?revision=34004

You probably want to comment out lines 481 - 483.

481 JToolBar toolBar = buildCompleteToolBar(embeddableComponent);
482             if (toolBar != null)
483                 cp.add(toolBar, BorderLayout.NORTH)

Remove your import for SwingViewBuilder and create your own class with those lines commented out.