aspose file tools*
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
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Launching Acrobat Reader" Watch "Launching Acrobat Reader" New topic
Author

Launching Acrobat Reader

Nitin Gaurz
Greenhorn

Joined: Oct 09, 2007
Posts: 4
Hi,
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.

Thanks
-Nitin
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38902
    
  23
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
/usr/bin/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
Sheriff

Joined: Oct 13, 2005
Posts: 38902
    
  23
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: 16070
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

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: 16070
    
  21

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

Joined: Mar 22, 2005
Posts: 41904
    
  63
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.


Ping & DNS - my free Android networking tools app
 
wood burning stoves
 
subject: Launching Acrobat Reader