This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes Launching Acrobat Reader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Launching Acrobat Reader" Watch "Launching Acrobat Reader" New topic

Launching Acrobat Reader

Nitin Gaurz

Joined: Oct 09, 2007
Posts: 4
I am using below code to launch Acrobat reader window to open PDF on windows

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);

My application and browser are windows. Now if I move application over to linux platform how can I achieve the same thing? Pardon me, seeking expert advise in advance (I didn't try it yet).My user will always be opening IE from windows.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Welcome to the Ranch.

You oughtn't to use Runtime.exec() on its own; you get two Streams representing standard error and standard output, both of which must be "emptied" otherwise your Runtime.exec() might throw an exception. Google for "when Runtime.exec() won't" (sic) and you will get an article by Dacosta from 2000 about this very problem. Look in the API at the ProcessBuilder class, which I am not familiar with, but may provide a simpler solution to that problem.

You don't usually use Acrobat on Linux, but evince. I tried this on a Bash shell
[Campbell@dhcppc0 ~]$ which evince
[Campbell@dhcppc0 ~]$ evince /home/Campbell/oldFolders/Eiffel/ECMA-367.pdf

. . . and a few seconds later ECMA-367 opened. So try and see what happens. Or tryYou will have various Streams to "empty" and various Exceptions to catch, but you should find the details in the API for Process and ProcessBuilder and in Dacosta.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
Sorry, but the Streams you want to get from the Process can be obtained with the getErrorStream() and getInputStream() methods.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Actually, since Acrobat Reader isn't supposed to be using any of the standard I/O files, having the process fail on a write to stdout/stderr is OK by me. I've had to fix problems where processes exec'ed and had stream I/O to contend with, but never had issues when they were mute. And setting up to handle streams that shouldn't exist is a lot of trouble.

I do tend to prefer Acrobat Reader over evince or XPDF myself. On my home system, I think it's in /usr/local/Acrobat/bin/acroread, but the machine I'm using right now just has it in /usr/bin/acroread.

An IDE is no substitute for an Intelligent Developer.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Have you considered embedding a PDF viewer into your Java code so that it is far more portable? For example Accessing a PDF Document with the Acrobat Viewer JavaBean. This is only one example - there are plenty of other portable solutions as well.

Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

Oooh, I like that idea! I'll have to remember it.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Well, the Acrobat Java Viewer Bean hasn't been updated for ages (at least since PDF 1.4 came along, and maybe before that), and has serious problems displaying PDFs using recent features. So it works for simple stuff, but nothing fancy.
I agree. Here's the link:
subject: Launching Acrobat Reader
It's not a secret anymore!