• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Launching Acrobat Reader

 
Nitin Gaurz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but the Streams you want to get from the Process can be obtained with the getErrorStream() and getInputStream() methods.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11886
198
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oooh, I like that idea! I'll have to remember it.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic