简体   繁体   中英

Goto specific page in PDF using C# Visual Studio

i'm using the AxAcroPDFLib.AxAcroPDF Tool from the toolbox and am having it a specific PDF when i click a button. I have a separate button (button2) and Textbox which i want to use to automatically move the PDF page to the page number entered into the TextBox when button2 is pressed.

The following code isn't working and i'm not sure what code to use to get it to work (and no i cannot just use the tools inside the PDF reader to do this as i need all the controls on monitor 1 and the PDF is displayed on Montior 2, i've sorted this part):

KEY: dsm = form2 | pdfview = the PDF reader inside form2

dsm.pdfview.setCurrentPage(TextBox1.Text);

This isn't working. i've also tried:

dsm.pdfview.setCurrentPage = TextBox1.Text;

Also not working. Any help would be great! Thanks.

The documentation clearly shows that the syntax is void setCurrentPage(LONG nPage)

You are passing a string in. You need to parse your string into an int or long before passing it in.

How to parse a string into a number

Also, based on the documentation your original method call was correct except for you passed in a parameter of the wrong type. Once you convert it, make that same call with the new parameter.

Here's the documentation from Adobe

Here's what I did. Thanks to Dmitry for pointing me in the correct direction:

KEY: dsm = form2 | pdfview = the Adobe PDF tool insterted into form2

private void srchPageNumBtn_Click(object sender, EventArgs e)
    {

        int nm = Int32.Parse(textBox2.Text);

       dsm.pdfview.setCurrentPage(nm);
    }

Works like a charm ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM