8

I would like to open a PDF file at named destination using WinForms (C#). Here is my code:

System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
myProcess.StartInfo.FileName = "Acrobat.exe";
myProcess.StartInfo.Arguments = "/A \"nameddest=Test2=OpenActions\" C:\\example.pdf";
myProcess.Start();

It always opens the file at page 1 even having the destination Test2 at page # 10. It basically ignores the destination parameter. However if I use another parameter like the page number it works fine. For example:

myProcess.StartInfo.Arguments = "/A \"page=5=OpenActions\" C:\\example.pdf";

will always open the PDF document at page 5.

Thanks in advance for your help

Russell Steen
  • 6,494
  • 6
  • 38
  • 56
  • Does it work if you execute the command from the command line? Have you tried other versions of Acrobat, or other systems? It might be an Acrobat bug, or maybe your install is bad? – Jason Sep 14 '09 at 21:09
  • I tried executing it from command line and it did not work. If I pass page number parameter it works but not using destinations. I even installed a new version of Acrobat a new computer and didn't have any success. –  Sep 15 '09 at 14:30
  • If it doesn't work form the command line, then this is not even a programming-related question. It's a question about Adobe Reader. This is not really the place for that kind of question - try asking at http://forums.adobe.com/community/adobe_reader_forums/adobe_reader – Allon Guralnek Sep 17 '09 at 08:39

5 Answers5

8

I use the following code:

string strNamedDestination  = "MyNamedDestination"; // Must be defined in PDF file.
string strFilePath = "MyFilePath.pdf";
string strParams = " /n /A \"pagemode=bookmarks&nameddest=" + strNamedDestination + "\" \"" + strFilePath + "\"";
Process.Start("AcroRd32.exe", strParams);

Note the "/n" inside the params. It makes Adobe to always open a new document. Otherwise, if the document was already opened, it doesn't move it to the right Named Destination. It depends on the behaviour you want for your application.

jcibar
  • 275
  • 6
  • 9
3

Regarding the Adobe documentation when opening a PDF document from a command shell, you can pass the parameters to the open command using the /A switch using the following syntax:

myProcess.StartInfo.Arguments = "/A \"nameddest=Test2=OpenActions\" C:\\example.pdf";

If I omit the OpenActions parameter everything works fine like:

myProcess.StartInfo.Arguments = "/A \"nameddest=Test2\" C:\\example.pdf";

I'm not sure why the OpenActions breaks opening the file but with omitting it works fine.

2

I have a csv with 5 columns. Column1 contains PDF names and Column5 pagenumbers. The executable displays the csv. When I doubleclick on a line in the csv the following code is executed :

ListViewItem item = lvwItems.SelectedItems[0];
Process myProcess = new Process();
myProcess.StartInfo.FileName = "Acrobat.exe";
myProcess.StartInfo.Arguments = "/A page=" + item.SubItems[4].Text + " " + item.Text;
myProcess.Start();

This opens the selected PDF which name is in item.Text on the page which pagenumber is in item.SubItems[4].Text

Dori
  • 915
  • 1
  • 12
  • 20
0

Have you set up the destinations? You need to be have the standard or professional versions of Adobe Acrobat in order to do this:

http://kb2.adobe.com/cps/317/317300.html

BFree
  • 102,548
  • 21
  • 159
  • 201
  • Yes, I'm using Adobe Acrobat 8 Standard Version 1.8.3. Inside Adobe all of the destinations seems fine. Clicking on any of them will navigate through the document. –  Sep 15 '09 at 02:40
0

Adobe Reader has a few bugs regarding opening to named destinations. Take a look at http://xenon.arcticus.com/open-pdf-named-destination-dde-c-c for some information and workarounds.