Open a pdf file at a specified page in C#

  • Thread starter Thread starter polocar
  • Start date Start date
P

polocar

Hello,
I'm writing a program in C#.
In the interface you have 2 textboxes in which you can specify the pdf
file name (with its position in the hard disk) and the page of that
file you want to go directly.
I would like that, when the user clicks on an appropriate "Open"
button, the pdf file would open exactly at that page.
I have found in other threads of the forum that the correct way to open
a pdf file in a C# program is to use

using System.Diagnostics;

namespace, and then the

Process.Start("namefile.pdf");

statement.
In this way the pdf document opens at page 1.
Is there a way to open it at the page specified in the textbox?

Thank you very much
 
Hi Octavio,
thank you for your response.
The document you suggested me lists the parameters you can use when you
open a pdf file from a command line statement (and one of these
parameters is the page number).
A typical command line statement example is:

Acrobat.exe /A "zoom=1000=OpenActions" "C:\example.pdf"

I have tried to adapt this concept to the C# Process.Start method.

These are my attempts:

Process.Start("C:\\example.pdf");
// It functions but opens the pdf file at page 1

Process.Start("C:\\example.pdf", "page=2");
// It functions but opens the pdf file at page 1

Process.Start("Acrobat.exe /A \"page=2\"", "C:\\example.pdf");
// It doesn't function (error: "impossible to find the specified
file",
// even if I created an "example.pdf" file in C:)

I also have studied the StartInfo property of Process class, but I
think it gives no more possibilities than the Start method used with
arguments.

In which way can I introduce the "page=<num>" parameter in the
Process.Start statement?

Thank you very much
 
Ok, finally I have found the solution.
After having introduced the namespace

using System.Diagnostics;

you can define a Process object and initialize its StartInfo property
in this way:

Process myProcess = new Process();
myProcess.StartInfo.FileName = "Acrobat.exe";
myProcess.StartInfo.Arguments = "/A \"page=2=OpenActions\"
C:\\example.pdf";
myProcess.Start();

The pdf file will open at page 2.
 
Back
Top