Open a pdf file programmatically at a named destination

后端 未结 5 1366
醉话见心
醉话见心 2020-12-03 15:32

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.Proc         


        
相关标签:
5条回答
  • 2020-12-03 16:03

    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.

    0 讨论(0)
  • 2020-12-03 16:04

    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

    0 讨论(0)
  • 2020-12-03 16:04

    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.

    0 讨论(0)
  • 2020-12-03 16:09

    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

    0 讨论(0)
  • 2020-12-03 16:14

    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.

    0 讨论(0)
提交回复
热议问题