Open a pdf file programmatically at a named destination

只谈情不闲聊 提交于 2019-11-27 14:49:46

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.

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.

Anne Schley

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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!