Can anyone help me out with the errors in this code for displaying PDF in Java swing?

509 views Asked by At

This code is to view a PDF in swing, but as I open any PDF the content is not visible and blank pages appear. I am using icepdf core and viewer jar files.

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);
    }}

Find the screenshots here..

Errors and warnings in the code

[enter image description here]

Output-view of PDF

enter image description here

1

There are 1 answers

2
Hendri On

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

Its seems you need JPEGImageDecoder for it http://www.java2s.com/Code/Jar/s/Downloadsunjaicodecjar.htm

Download the JAR and add it to your build path libraries