首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从icePDF查看器禁用工具栏

从icePDF查看器禁用工具栏
EN

Stack Overflow用户
提问于 2013-12-23 19:22:47
回答 2查看 2.4K关注 0票数 1

我正在用icePDF尝试一个示例。一切正常,但我需要禁用出现在顶部的工具栏。我尝试了几种方法,但都不起作用。有没有人能帮我一下?下面是我的代码。

代码语言:javascript
复制
//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);  
    }


}
EN

回答 2

Stack Overflow用户

发布于 2014-12-19 00:12:18

代码语言:javascript
复制
private SwingController controller;
controller = new SwingController();
SwingViewBuilder viewBuilder = new SwingViewBuilder(controller, properties);
JPanel panel = viewBuilder.buildViewerPanel();
controller.setToolBarVisible(false);

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

票数 2
EN

Stack Overflow用户

发布于 2014-02-26 01:24:35

有两种方法可以做到这点。

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行。

代码语言:javascript
复制
481 JToolBar toolBar = buildCompleteToolBar(embeddableComponent);
482             if (toolBar != null)
483                 cp.add(toolBar, BorderLayout.NORTH)

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20742512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档