0

I Need to open a specific page of a pdf file.

I tried:

 private void Button_Click_20(object sender, RoutedEventArgs e)
        {
            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            process.StartInfo = startInfo;
            startInfo.Arguments = "/A \"page=5\"";
            startInfo.FileName = @"J:temp.pdf";
            process.Start();
        }

but it still opens the first page. Still unsolved.

if i Change to this

private void Button_Click_20(object sender, RoutedEventArgs e)
        {
            {
            Process process = new Process();
            process.StartInfo.Arguments = @"/A \"page=5\" \"J:\\temp.pdf"";
            process.StartInfo.FileName = @"J:\temp.pdf";
            process.Start();
        }        
}

i get seven Errors (Semicolon, page no context...)

check2410
  • 21
  • 5

1 Answers1

-1

It's unclear on how the arguments need to look like. Assuming it's J:\temp.pdf /A page=5

this should work:

 Process process = new Process();
 process.StartInfo.Arguments = @"/A page=5";
 process.StartInfo.FileName = @"J:\temp.pdf";
 process.Start();

However I'm not sure if you can pass arguments to a file name like this, I'd assume you need to call your PDF viewer's executable and pass both the file name and the page argument like in the question already linked in the comments:

 ProcessStartInfo startInfo = new ProcessStartInfo();
 startInfo.FileName = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
 startInfo.Arguments = "/A \"page=5\" \"E:\\Users\\You\\temp.pdf\"";
 Process.Start(startInfo);

This works on my machine (replace paths as needed of course).

Lennart
  • 9,657
  • 16
  • 68
  • 84