Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to launch Acrobat or Preview to open a PDF



starting from 10.4 (I think) open command can send argument to the application too
also you can use Safari, to open pdf as well
in mac os x you can consider other options:
PDFKit component via CocoaComponent
or you can use webkitjava to open pdf file



On Jan 20, 2006, at 8:45 PM, Ian Cheyne wrote:

I suspect that you have a space in the path to your file. Instead use the alternative exec method as follows which will work if spaces are in your (absolute path) filename:

Runtime.getRuntime().exec(new String[] { "open", fileName });

Best Regards,

Ian Cheyne



On 21 Jan 2006, at 01:24, Dan Crow wrote:

Hi guys,

I'm trying to launch either Adobe Acrobat or Preview.app from my Java application so I can display a PDF file to the user. I'm doing this on Mac by using Runtime.exec to invoke the open command.

I've tried various different open commands through the following code:


private static void launch(String fileName, String applicationName)
{
String cmd = "open " + fileName;
try
{
System.out.println("Executing command: " + cmd);
Runtime.getRuntime().exec(cmd);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "Could not open " + applicationName);
e.printStackTrace();
}
}


Whatever I set cmd to, nothing happens. The application doesn't launch, I don't get an error message or exception, it just silently fails.

Two odd things:

1) The same code opens my default web browser just fine if I pass a URL to this method in the fileName parameter

2) If I invoke the exact command that's println'ed out from Terminal, then the PDF file is opened as expected, so the filename (which is an absolute path) is valid.

Can anyone offer any clues about this? What have I missed?

Many thanks as always,

Dan

--
Dan Crow
VP of Product and Technology
email@hidden

Blurb, Inc.

88 Kearny Street, Suite 1610
San Francisco, CA 94108

415.362.2067 x663 (office)
415.290.6184 (mobile)
415.362.2078 (fax)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

Dmitry Markman

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Trying to launch Acrobat or Preview to open a PDF (From: Dan Crow <email@hidden>)
 >Re: Trying to launch Acrobat or Preview to open a PDF (From: Ian Cheyne <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.