Search code examples
javaacrobatpdfview

open PDF file saved in project directory using java with Acrobat viewer JavaBean API


I am using java programming to display a pdf file saved in the project directory. I have tried this code

import java.awt.BorderLayout;
import java.io.FileInputStream;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.adobe.acrobat.Viewer;

public class lecteurPDF extends JPanel{
    private static final long serialVersionUID = 1L;
private Viewer viewer;

public lecteurPDF(String nomfichier) throws Exception{
    this.setLayout(new BorderLayout());

    viewer = new Viewer();
    this.add(viewer, BorderLayout.CENTER);
    FileInputStream fis = new FileInputStream(fliename);
    viewer.setDocumentInputStream(fis);
    viewer.activate();
}
public static void main(String[] args) throws Exception {

    String fliename= "a.pdf";
    lecteurPDF lecteur = new lecteurPDF(fliename);
    JFrame f = new JFrame("Lecteur PDF");
    f.setSize(1024,768);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    f.getContentPane().add(lecteur);
}
}

but unfortunately I got this error when I running this program.

Exception in thread "main" java.lang.NoClassDefFoundError: com/apple/mrj/MRJAboutHandler
at displaypdf.lecteurPDF.<init>(lecteurPDF.java:19)
at displaypdf.lecteurPDF.main(lecteurPDF.java:28)
Caused by: java.lang.ClassNotFoundException: com.apple.mrj.MRJAboutHandler
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more

Can anybody help me to fix this problem please.


Solution

  • It looks you are missing MRJToolkitStubs from your classpath as this contains com.apple.mrj.MRJAboutHandler. If needed, a download to the jar file can be found: http://maven.ibiblio.org/maven/mrj/jars/