i am working on a java based tool, which should search for PDF files on selected directories and which should search for special words/sentences in this PDF files. After that a JList shows the files which fits and with a double-click on one of these entries the PDF Reader (Adobe Reader) should open this file directly on the page where the word/sentence appeares.
I tried two different things.
Runtime.exec:
try{
Runtime.getRuntime().exec("rundll32" + " " + "url.dll,FileProtocolHandler /A page=4" + " " + o.toString());
}catch(IOException ex) {
ex.printStackTrace();
}
Desktop open:
if(Desktop.isDesktopSupported()) {
try{
Desktop d = Desktop.getDesktop();
d.open(new File(o.toString()));
}catch(IOException ex) {
ex.printStackTrace();
}
}
Is there a way to start the PDF Reader with parameters like "page=4" to jump directly to the right page?
Thanks in advance
One of the problem you might face is not being able to directly call acrobat, if not in the Path of the computer. The solution uses two Windows commands : assoc and ftype to retrieve acrobat executable path.
Once found, you just have to build the command line as expected in acrobat's documentation :
I came with the following solution:
Beware, the code is highly optimistic for the sake of readability, several tests has to be made to ensure that the commands return the expected result. Additionally, this code has a Java6 syntax that could certainly benefit an upgrade to Java7's "try with resources" and nio.