File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with opening pdf file on linux machine

 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

As part of my project requirement i have to write a code in java which when executed should open a pdf file (being created) on Linux machine.

I am using Runtime.exec() but not able to find correct command to open pdf file.

Please help me as it is very urgent.

 
Carl John
Ranch Hand
Posts: 47
Eclipse IDE Java Netbeans IDE
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Prefer Desktop class over Runtime class...

have this snippet..

desk = java.awt.Desktop.getDesktop ();
desk.open (new java.io.File ("sample.pdf"))

 
Kiaamaa Liammes
Ranch Hand
Posts: 32
Eclipse IDE Java Objective C
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Urgency here
 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is still not working. Can any body please guide me.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Gaurav wrote:It is still not working. Can any body please guide me.



Guide you how? You haven't told us how it's failing. If you told us the actual error message, I'm sure we could be more helpful.

Is it not finding a program that opens PDF files? Perhaps one isn't installed. xpdf, kpdf, and acroread are three possibilities. The Desktop class will only work if there's a common desktop environment set up and configured to be able to read PDF files; there's no guarantee of that.

Is it producing an error that says it can't find the file? Maybe you're using backslashes in path names, which are inappropriate on Linux.
 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest Friedman,


Even on linux machine below code is not getting executed :

java.awt.Desktop desk = java.awt.Desktop.getDesktop();
if(java.awt.Desktop.isDesktopSupported())

System.out.println("Desktop supported on Linux");
else

System.out.println("Desktop not supported on Linux");

Not a single out of these two statements are getting executed.

Following error is coming

java.lang.UnsupportedClassVersionError

Any clue why it is happening. Please let me know any other information is required

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Gaurav wrote:Following error is coming

java.lang.UnsupportedClassVersionError

Any clue why it is happening. Please let me know any other information is required

Aha, this is what we needed to know!

This error means that you are compiling your classes on a newer version of Java then you are trying to run them on. For example, you get this error when you compile your source code with JDK 6 and then try to run it on Java 5 or older.

What version of the JDK are you using and what version of Java is running on the Linux machine?
 
Kumar Gaurav
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I immediately overcame java.lang.UnsupportedClassVersionError this error as there was JVM version mismatch.
I tried running following code

public class DesktopSupport {

public static void main (String[] args) {

if(java.awt.Desktop.isDesktopSupported()) {
System.out.println("Desktop supported in Env");
} else {
System.out.println("Desktop not supported in Env");
}
}
}

After that following error is coming

bash-3.2$ javac DesktopSupport.java
bash-3.2$ java DesktopSupport
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$100(X11GraphicsEnvironment.java:52)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:155)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:89)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at java.awt.Toolkit$2.run(Toolkit.java:834)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:826)
at java.awt.Desktop.isDesktopSupported(Desktop.java:151)
at DesktopSupport.main(DesktopSupport.java:7)
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't open a PDF file in a graphical application without a windowing session (GNOME, KDE, Xfce, Blackbox, etc) to show that application. You can try adding -Djava.awt.headless=true as a parameter to the JVM (so before the class name) but most likely that will make the operation not supported.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic