-2

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

c0der
  • 18,467
  • 6
  • 33
  • 65
  • 1
    Do not post an image of your stack trace. Edit your question, and copy and paste the actual text of the stack trace into the question. – VGR Apr 04 '18 at 15:23

1 Answers1

0

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

Hendri
  • 59
  • 6
  • 2
    Please don't just post some tool or library as an answer. At least demonstrate [how it solves the problem](http://meta.stackoverflow.com/a/251605) in the answer itself. – Zoe Apr 04 '18 at 15:17
  • @Zoe Updated my answer,Thanks – Hendri Apr 04 '18 at 15:48