0

我正在使用 SWING 创建一个小型桌面应用程序,我需要在预览面板中显示 PDF。为了达到这个要求,我正在使用具有以下版本的 ICEPDF 库

<!-- https://mvnrepository.com/artifact/org.icepdf.os/icepdf-core -->
<dependency>
    <groupId>org.icepdf.os</groupId>
    <artifactId>icepdf-core</artifactId>
    <version>6.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.icepdf.os/icepdf-core -->
<dependency>
    <groupId>org.icepdf.os</groupId>
    <artifactId>icepdf-viewer</artifactId>
    <version>6.1.2</version>
</dependency>

或者

<!-- https://mvnrepository.com/artifact/org.icepdf/icepdf-core -->
<dependency>
    <groupId>org.icepdf</groupId>
    <artifactId>icepdf-core</artifactId>
    <version>4.1.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.icepdf/icepdf-core -->
<dependency>
    <groupId>org.icepdf</groupId>
    <artifactId>icepdf-viewer</artifactId>
    <version>4.1.1</version>
</dependency>

但它不能正常工作

当我org.icepdf - icepdf-core and org.icepdf - icepdf-viewer当时使用 pdf 时显示如下 在此处输入图像描述

pdf中有更多文字我无法分享原始pdf内容,否则我会告诉你

当我当时使用org.icepdf.os - icepdf-core and org.icepdf.os - icepdf-viewer时,我得到了以下异常

The type org.icepdf.core.views.DocumentViewController cannot be resolved. It is indirectly referenced from required .class files

请问如何在我的预览面板中显示整个 pdf 内容?

我的整个源代码如下

                    JPanel panel = new JPanel();
                    panel.setBounds(470, 0, 600, 700);
    
                    // Construct a PropertiesManager from the default properties
                    // file and default message bundle
                    PropertiesManager properties = new PropertiesManager(
                            System.getProperties(),
                            ResourceBundle
                                    .getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
    
                    // Build a SwingViewFactory configured with the controller
                    SwingViewBuilder factory = new SwingViewBuilder(controller,
                            properties);
    
                    // Use the factory to build a JPanel that is pre-configured
                    // with a complete, active Viewer UI.
                    viewerComponentPanel = factory.buildViewerPanel();
                    viewerComponentPanel.setPreferredSize(new Dimension(580, 650));
                    viewerComponentPanel.setMaximumSize(new Dimension(580, 650));
                    // add copy keyboard command
                    ComponentKeyBinding.install(controller, viewerComponentPanel);
    
                    controller.setPageViewMode(
                            DocumentViewControllerImpl.ONE_COLUMN_VIEW, false);
    
                    // add interactive mouse link annotation support via callback
                    controller.getDocumentViewController().setAnnotationCallback(
                            new org.icepdf.ri.common.MyAnnotationCallback(
                                    controller.getDocumentViewController()));
    
                    // Create a JFrame to display the panel in
                    panel.add(viewerComponentPanel, BorderLayout.CENTER);
    
                    contentPane.add(panel);

                    controller.openDocument(file);
4

0 回答 0