Need to call Acrobat Distiller

I am callingAcrobat Distiller from my code as

Process procView=Runtime.getRuntime().exec("C:/Program Files/Adobe/Acrobat 5.0/Distillr/acrodist.exe");

, but I do not want to fix the path sinceacrodist.exe may not be in the same path in different systems.

And also once it opens,

1. When the user chooses File->Open, the path should be fixed toC:\temp, and also

2. How do I fix option inJob Options, for instance asScreen

[525 byte] By [sony_tja] at [2007-11-27 3:10:17]
# 1

Well you can do a search for acrodist.exe from within your application (slow), or you can let the users configure it themselves by providing a setup that allows the users to choose the location of acrobat distiller (fast). I would go for the second option, it may require an additional step for the users, but at least they will know that they need acrobat distiller before your application will work.

As for your other questions, forget about that. You cannot control applications from Java or any other language without a proper API to do so.

gimbal2a at 2007-7-12 3:59:56 > top of Java-index,Java Essentials,New To Java...
# 2

You remember that all on windows is save inside REGEDIT, so, you need check the correct key to find the real path.

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class FindProgramOnWindows {

public static void main(String args[]) {

System.out.println("Buscando Firefox");

System.out.println(new FindProgramOnWindows().find("firefox.exe"));

}

public String find(String exeName) {

String path = "";

try {

Process r = Runtime.getRuntime().exec(

"reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\" +

"Microsoft\\Windows\\CurrentVersion\\App Paths\\" +

exeName + "\"");

BufferedReader buffer = new BufferedReader(

new InputStreamReader(r.getInputStream()));

String line = "";

String exeNameRegexp = exeName.replaceAll("\\.", "\\\\.");

while ((line = buffer.readLine()) != null) {

Pattern p = Pattern.compile(".+\\w:\\\\.+" + exeNameRegexp,

Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher(line);

m.matches();

if (m.matches()) {

String param[] = line.split("\t");

path = param[param.length-1];

break;

}

}

buffer.close();

} catch (Exception e) {

e.printStackTrace();

}

return path;

}

}

danjaredga at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 3

Sorry... change this part

while ((line = buffer.readLine()) != null) {

Pattern p = Pattern.compile(".+\\w:\\\\.+" + exeNameRegexp,

Pattern.CASE_INSENSITIVE);

Matcher m = p.matcher(line);

m.matches();

if (m.matches()) {

String param[] = line.split("\t");

path = param[param.length-1];

break;

}

}

for this:

Pattern p = Pattern.compile(".+\\w:\\\\.+" + exeNameRegexp,

Pattern.CASE_INSENSITIVE);

while ((line = buffer.readLine()) != null) {

Matcher m = p.matcher(line);

m.matches();

if (m.matches()) {

String param[] = line.split("\t");

path = param[param.length-1];

break;

}

}

it's more correct.

danjaredga at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 4

I tried running the code given by you as shown below, but why am I getting the following error

public class FindProgramOnWindows

{

public static void main(String args[])

{

System.out.println("Buscando Firefox");

//System.out.println(new FindProgramOnWindows().find("firefox.exe"));

System.out.println(new FindProgramOnWindows().find("acrodist.exe"));

}

public String find(String exeName)

{

String path = "";

try

{

Process r = Runtime.getRuntime().exec("reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\" +"Microsoft\\Windows\\CurrentVersion\\App Paths\\" + exeName + "\"");

BufferedReader buffer = new BufferedReader(new InputStreamReader(r.getInputStream()));

String line = "";

String exeNameRegexp = exeName.replaceAll("\\.", "\\\\.");

Pattern p = Pattern.compile(".+\\w:\\\\.+" + exeNameRegexp, Pattern.CASE_INSENSITIVE);

while ((line = buffer.readLine()) != null)

{

Matcher m = p.matcher(line);

m.matches();

if (m.matches())

{

String param[] = line.split("\t");

path = param[param.length-1];

break;

}

}

buffer.close();

} catch (Exception e)

{

e.printStackTrace();

}

return path;

}

}

Error got

Buscando Firefox

java.io.IOException: CreateProcess: reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\acrodist.exe" error=2

at java.lang.ProcessImpl.create(Native Method)

at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)

at java.lang.ProcessImpl.start(ProcessImpl.java:30)

at java.lang.ProcessBuilder.start(ProcessBuilder.java:451)

at java.lang.Runtime.exec(Runtime.java:591)

at java.lang.Runtime.exec(Runtime.java:429)

at java.lang.Runtime.exec(Runtime.java:326)

at Trying.FindProgramOnWindows.find(FindProgramOnWindows.java:40)

at Trying.FindProgramOnWindows.main(FindProgramOnWindows.java:30)

sony_tja at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 5

find in the regedit the key and you make sure that the key exist... also try run the command in the console.

I tested in Windows XP SPK2 32 bits, the output was this:

C:\Documents and Settings\Administrator>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Cur

rentVersion\App Paths\firefox.exe"

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe

<NO NAME>REG_SZ C:\Program Files\Mozilla Firefox\firefox.exe

PathREG_SZ C:\Program Files\Mozilla Firefox

so, I'm sure that the error happen becasue the command "reg" have sintax diferent in your version windows

danjaredga at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 6
if is posible you send me wath is the line where the error happened
danjaredga at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 7

In the command prompt, I gave the following command

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\acrodist.exe"

, but the error thrown is

'reg' is not recognized as an internal or external command,

operable program or batch file.

Message was edited by:

sony_tj

Message was edited by:

sony_tj

sony_tja at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...
# 8

please, send me the windows version. but the problem is the syntax command.

the version 95, 98 and Me have the "regedit" command.

http://www.eolsoft.com/freeware/registry_jumper/regedit_switches.htm

In 2000 NT, XP have the "reg" command.

http://www.computerhope.com/reg.htm

And, I don't have idea which it's command on Vista.

So the idea is capture the windows standard output and process this output, analyze with regular expression, and finally extract the string with the path.

In 95, 98 and Me, I'm not sure if is possible generate a standard output, but you can export the key and values, and after you can read the file and get the path.

In your application can validate the windows version with "String s = System.getProperty("key");", the example is this page:

http://www.rgagnon.com/javadetails/java-0150.html

Good luck...

danjaredga at 2007-7-12 3:59:57 > top of Java-index,Java Essentials,New To Java...