-2

此代码用于查看 PDF,但是当我打开任何 PDF 时,内容不可见并且出现空白页。我正在使用 icepdf 核心和查看器 jar 文件。

public class PDFView{

    public static void main(String[]args) {

        SwingController controller = new SwingController();
        SwingViewBuilder factory = new SwingViewBuilder(controller);
        controller.setIsEmbeddedComponent(true);

        DocumentViewController viewController = controller.getDocumentViewController();

        JPanel viewerComponentPanel = factory.buildViewerPanel();
        ComponentKeyBinding.install(controller, viewerComponentPanel);

        controller.getDocumentViewController().setAnnotationCallback(
                new org.icepdf.ri.common.MyAnnotationCallback(
                        controller.getDocumentViewController()));

        JFrame applicationFrame = new JFrame();
        applicationFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        applicationFrame.getContentPane().setLayout(new BorderLayout());
        applicationFrame.getContentPane().add(viewerComponentPanel,BorderLayout.CENTER);
        applicationFrame.getContentPane().add(factory.buildCompleteMenuBar(),BorderLayout.NORTH);

        controller.setPageViewMode(DocumentViewControllerImpl.ONE_PAGE_VIEW, false);

        applicationFrame.pack();
        applicationFrame.setVisible(true);
    }}

在这里找到截图..

代码中的错误和警告

[ 在此处输入图像描述]

PDF的输出视图

在此处输入图像描述

4

1 回答 1

0

java.lang.noClassDefFoundError : com.sun.image.codec.jpeg.JPEGImageDecoder

看来您需要 JPEGImageDecoder http://www.java2s.com/Code/Jar/s/Downloadsunjaicodecjar.htm

下载 JAR 并将其添加到构建路径库中

于 2018-04-04T15:17:39.080 回答