open a pdf in a swing jpanel
888525Nov 1 2011 — edited Nov 3 2011I have a url for a pdf file and I want to open that file in a swing jpanel.I have upgraded to Java 1.6.0_27 and previously had 1.5.0_06
In Java 1.5 ,I was using jdic to do this for that the user needed to download jdic setup on their desktop to view images
but now I dont find any documentaion for java 1.6.0_27 and jdic setup.So i thought of doing this without the jdic .In java 5, I was using the beow code to show the pdf in swing jpanel.This basically embedds pdf in a web browser and then add it to swing jpanel.
import org.jdesktop.jdic.browser.*;
import org.jdesktop.jdic.browser.internal.*;
WebBrowserUtil.enableDebugMessages(false);
WebBrowserUtil.getDebug();
WebBrowser webBrowser = null;
URL pdfURL = testUrils.getPdf("Pathof .pdf");
try {
webBrowser = new WebBrowser();
webBrowser.setDebug(false);
webBrowser.setURL(pdfURL);
} catch (java.lang.UnsatisfiedLinkError el) {
}
catch (Exception e) {
//System.out.println(e.getMessage());
System.out.println("Error: " + e.getStackTrace());
}
JPanel pantestBrowser= new JPanel();
pantestBrowser.setLayout(new BorderLayout());
pantestBrowser.setPreferredSize(new Dimension(700, 500));
pantestBrowser.setLocation(0,0);
pantestBrowser.add(webBrowser, BorderLayout.CENTER);
I want to do the same thing without the jdic webbrowser.Is there a way out to do this?
I tried to do with java.awt.desktop
Desktop desktop=Desktop.getDesktop
desktop.browse(pdfurl.toURI())
This opens the pdf in a new adobe window and not inside the jpanel.
Thanks,