tags:

views:

98

answers:

1

My question is similar to "How can I programmaticly open a pdf at a certain point?", but the PDF is local, not on a web server.

I need a way to jump to a given page in a PDF that is on the users computer, that works across versions of Acrobat (or using an alternative PDF viewer like Foxit Reader). The PDF is going to be called from a Java app (it is only used on Windows, so cross-platform isn't a must), and right now it works with:

int pageNum = 24;
String manualPath = "C:\\Program Files\\Foo\\Bar\\Docs\\RefMan.pdf";
String acrordPath = "C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe";
String cmdString = "\"" + acrordPath + \" /A \"page=" + pageNum + 
    "=OpenActions\" \"" + manualPath + \"";
Process p = Runtime.getRuntime().exec(cmdString);

Obviously this will only work if the end user is using Acrobat 8 for 32bit, and installed it in the default location. I next tried using:

rundll32 url.dll,FileProtocolHandler file:///C:/Program%20Files/Foo/Bar/Docs/RefMan.pdf#page=24

thinking that this would open the users browser and jump to that page, but it simply opened Acrobat on page 1.

So I'm stumpped, and asking for help.

A: 

I ended up implementing this by using this code to call reg.exe and parse the output from HKLM\SOFTWARE\Classes.pdf to see if its the AcroExch class, then getting the command line from HKLM\SOFTWARE\Classes\AcroExch.Document\Shell\Open\Command.

Its hacky, but it works.

mwalling