Navigating PDF files

Bruce_P

Member
Joined
Jul 3, 2009
Messages
6
Programming Experience
10+
Hi all,

I'm trying to add some help functionality to a vb.net app by loading a PDF file and displaying a specific page in the document. This is a PDF that I don't have the original source to so I can't modify it. I can launch the Adobe Reader and have it display a particular page within a PDF without any problems using the following (I'm not hardcoding these values in the app, this is just for demonstration purposes):

Dim adobePath as String = "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
Dim params as String = "/A zoom=100&page=3 c:\temp\foo.pdf"
System.Diagnostics.Process.Start(adobePath, params)

Adobe documents how to pass parameters to Acrobat in this document: http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters_v9.pdf

What I'm trying to figure out now is how to switch to a different page. If a user is running my app and they view one help page I want to be able to switch to another help page on demand if they ask for help elsewhere.

If I launch the help file as described above, the Adobe Reader launches and shows pages 3 of foo.pdf. If I then scroll to another page of the PDF then try to execute the above code a second time it doesn't revert back to page 3. Since this is just trying to re-launch the application that makes sense - the application is already running...

So I tried creating a form with a WebBrowser object in it and load the pdf this way:

HelpForm.WebBrowser1.Navigate("file:///c:/temp/foo.pdf#zoom=100&page=3")

Once again when initially invoked it displays the PDF file on page 3 as requested. However if I then try to navigate to a different page it again ignores the parameters. I would have hoped that since the URL has changed (say to page=10) that the browser object would recognize the change and display the new page, but no dice.

So the next thing I tried was deleting the web browser object then re-creating it, hoping that it would re-initialize everything. But even that doesn't work. So if I invoke the above Navigate method, manually scroll the PDF to page 10, dispose the form that WebBrowser1 is in, recreate the form, and invoke the above Navigate method a second time then the PDF still shows up on page 10 and not page 3. I've even gone so far as to try to dynamically create the WebBrowser object and dispose of it each time but even that doesn't work.

Any suggestions as to how I might be able to get this to work? It's starting to look like the only way I might be able to do it is to have my app invoke the Acrobat Reader to display the PDF but first terminate any running instances of Acrobat. That's a pretty ugly hack as far as I'm concerned and I'm not even sure how to go about doing it.

Thanks,

-Bruce
 
You can also add a "Adobe Pdf Reader" control to a form. Choose items for Toolbox and select it in COM list, then add it to form. Use methods LoadFile and setCurrentPage.
 
thank you very much, I was trying to build a simple bookmark application and I wanted to post a question about how to open PDF file and assign a page number to be opened

but how to use these function, I mean what references and Libraries to add to my project.
e.g.: "Acrobat Access 3.0 type liberary" or what are needed

thank you.
 
u-sef said:
I mean what references and Libraries to add to my project.
Have a look at post 2 again, all you need is explained there.
 
but how to use these function, I mean what references and Libraries to add to my project.
e.g.: "Acrobat Access 3.0 type liberary" or what are needed

From the Tools menu click on "Choose Toolbox Items". In the window that appears click on the "COM Components" tab and check "Adobe PDF Reader". You'll then see an Adobe PDF Reader icon appear in your Toolbox.
 
Back
Top