【问题标题】:Can anyone help me out with the errors in this code for displaying PDF in Java swing?任何人都可以帮助我解决此代码中在 Java swing 中显示 PDF 的错误吗?
【发布时间】:2018-04-04 15:12:29
【问题描述】:

此代码用于查看 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 的输出视图

【问题讨论】:

  • 不要发布堆栈跟踪的图像。编辑您的问题,并将堆栈跟踪的实际文本复制并粘贴到问题中。

标签: java swing pdf pdfview icepdf


【解决方案1】:

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

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

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

【讨论】:

  • 请不要只发布一些工具或库作为答案。至少在答案本身中展示how it solves the problem
  • @Zoe 更新了我的答案,谢谢
猜你喜欢
  • 2018-06-03
  • 1970-01-01
  • 1970-01-01
  • 2011-06-03
  • 1970-01-01
  • 1970-01-01
  • 2014-04-03
  • 1970-01-01
  • 2012-11-30
相关资源
最近更新 更多