tags:

views:

83

answers:

2

Is there any way to have a code where it can be used to open PDF file in Java application but do not side to any platform. I mean using batch file in Windows could do that. Can it be any other way to have platform independent code to open PDF on fly.

+5  A: 

I'd try Desktop.open(File), which:

Launches the associated application to open the file.

So this code should do the trick:

if (Desktop.isSupported()) {
    try {
        File myFile = new File("/path/to/file.pdf");
        Desktop.getDesktop().open(myFile);
    } catch (IOException ex) {
        // no application registered for PDFs
    }
}
Michael Myers
A: 

You can use Runtime to execute and script and there are also several Java PDF viewers out there (ie Icepdf, JPedal, PDFRenderer).

mark stephens
Thanks for the suggestions...;)
Mr CooL