2

我正在尝试使用 icePDF 的示例。一切正常,但我需要禁用出现在顶部的工具栏。我尝试了几件事,但它不起作用。有人可以帮我解决这个问题。下面是我的代码。

//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);  
    }


}
4

2 回答 2

3
private SwingController controller;
controller = new SwingController();
SwingViewBuilder viewBuilder = new SwingViewBuilder(controller, properties);
JPanel panel = viewBuilder.buildViewerPanel();
controller.setToolBarVisible(false);

您必须将工具栏设置为不可见,因为 icePdf 在 PDF 文档中查找该属性,并在没有打开文档时用默认值覆盖您的设置!

于 2014-12-18T16:12:18.367 回答
1

有两种方法。

1)按照此示例将所有工具栏设置为false。 http://www.icesoft.org/JForum/posts/list/17673.page#stash.48ICrL2A.dpbs

2)您可以通过编辑源代码来修改或删除工具栏SwingViewBuilder

这是代码的链接:http ://sventon.icesoft.org/svn/repos/repo/show//icepdf/trunk/icepdf/viewer/src/org/icepdf/ri/common/SwingViewBuilder.java?revision =34004

您可能想要注释掉第 481 - 483 行。

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

删除您的导入SwingViewBuilder并创建您自己的类,并将这些行注释掉。

于 2014-02-25T17:24:35.133 回答