【问题标题】:Disabling toolbar from icePDF viewer从 icePDF 查看器禁用工具栏
【发布时间】:2014-01-11 14:40:19
【问题描述】:

我正在尝试使用 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);  
    }


}

【问题讨论】:

    标签: swingbuilder icepdf


    【解决方案1】:
    private SwingController controller;
    controller = new SwingController();
    SwingViewBuilder viewBuilder = new SwingViewBuilder(controller, properties);
    JPanel panel = viewBuilder.buildViewerPanel();
    controller.setToolBarVisible(false);
    

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

    【讨论】:

      【解决方案2】:

      有两种方法。

      1) 按照此示例将所有工具栏设置为 false。 http://www.icesoft.org/JForum/posts/list/17673.page#sthash.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 的导入并创建自己的类,并注释掉这些行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-29
        • 1970-01-01
        • 1970-01-01
        • 2020-04-03
        • 1970-01-01
        • 2017-11-21
        • 2011-03-05
        相关资源
        最近更新 更多