Open a pdf file programmatically at a named destination

17,047

Solution 1

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.

Solution 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

Share:
17,047

Related videos on Youtube

Russell Steen
Author by

Russell Steen

Personally I find StackOverflow to be good for personal development. We should all spend some time trying to debug code without a compiler now and then. Like Hiking? -- follow me here: http://hikingfoxes.com/

Updated on April 19, 2022

Comments

  • Russell Steen
    Russell Steen about 2 years

    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