Link to home
Start Free TrialLog in
Avatar of BillPowell
BillPowell

asked on

Open a PDF document and goto specific page

I have a manual that is online as a pdf document.  From an Access command button, I would like to open that pdf and goto a specific page.  The specific page would depend on a textbox value that would allow the code to reference a table to see which page to navigate too.  See table structure below:

tblLUBpage

Zone    Page
RS-1      29
RS-2      31

I have opened pdf's from Access before, but never done any navigating.  How should I start with this?
Avatar of jadedata
jadedata
Flag of United States of America image

Greetings BillPowell!

  Bill:   did they pass a law in your state that requires the questions to get so difficult ??
  This is looking like a job for the Adobe API (if such a thing exists) to access the function you're looking for.
  I'll see if I can find it out the for you dude!

regards
jack
Bill, did I ever give you the link to the SDK? If so, lookup the documentation for the JSObject (you need VB6 for this). With this VB->JavaScript bridge you can then use the JavaScript objects and jump to any page you want. If you don't have the API yet, go to this page and download the _VERSION 5_ (this was the last one that was distributed for free): http://partners.adobe.com/asn/acrobat/download.jsp#fullinstall - you need to create a free web account.
You can also pass a command line argument to Acrobat to have to open a PDF document on a specific page. You can find more about all the "PDF Open Parameters" in this document: http://partners.adobe.com/asn/acrobat/sdk/public/docs/PDFOpenParams.pdf
One more method (which does not require VB6, so you should be OK with VBA). You can use the OLE automation interface and use the AcroExch.AVPageView object's Goto method. It takes a page number. Just keep in mind that Acrobat starts to count pages with page 0 (that's the first page in the document).

The JavaScript code for changing the page (in this example to page 5) is:
this.numPage = 4;
This is a method in the Doc object.

Avatar of BillPowell
BillPowell

ASKER

Sorry for the delay.  Took me a while to look into that, but Ive downloaded the SDK and managed to use the following code to open a PDF by passing the procedure a URL.  Now my problem is how to implement the page navigation.  I know your not fluent in VBA but perhaps youll have some idea where I need to go from here.  Also, Jack may still be listening in on this one.  He knows VBA quite well:

    Function PdfCheck(ByVal URL As String)
    On Error Resume Next
        Dim AcroApp As Acrobat.CAcroApp
        Dim PDDoc As Acrobat.CAcroPDDoc
        Set AcroApp = CreateObject("AcroExch.App")
        Set PDDoc = CreateObject("AcroExch.PDDoc")
       
        AcroApp.Show
        PDDoc.Open (URL)
        PDDoc.OpenAVDoc (URL)
       
    End Function
Also, out of curiosity, I noticed that when opening a pdf this way it opens lightening fast.  No font loading, no waiting while viewing the Adobe logo.  Why is that?
Please keep in mind that I don't program in VB (not at all!), so this may be just stupid, but I'll try anyway :-)


Dim AVDoc As Acrobat.CAcroAVDoc
Dim AVPageView As Acrobat.CAcroAVPageView
Dim AcroApp As Acrobat.CAcroApp
 
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")

AVDoc.Open(URL, "")

Set AVPageView = AVDoc.GetAVPageView
AVPageView.Goto(4)

For this to work, you need an AVDoc instead of a PDDoc (an AVDoc is the document when it's displayed in Acrobat, a PDDoc is opened "behind the scenes" and is not displayed).



It only opens lighning fast if you do this twice (or with Acrobat already running). When you exit your program, Acrobat is still running in the background, so it does not have to be loaded again.
Ok, now were getting somewhere.  The code below now works perfect for any pdf that is on our network.  It wont work with pdf documents on the web though.  When I try to use this code and pass a web url then I first get an error with Acrobat:  There was an error opening this document. The filename, directory name, or volume label syntax is incorrect.  Then I get a VB runtime error.  This is not a show stopper for me.  Im happy just to figure out how to do this with any pdf.  I just though it might be something simple that Im doing wrong.  


Private Function PDF_Navigate(ByVal URL As String, intPage As Integer)

Dim AVDoc As Acrobat.CAcroAVDoc
Dim AVPageView As Acrobat.CAcroAVPageView
Dim AcroApp As Acrobat.CAcroApp
 
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")

AcroApp.Show
AVDoc.Open URL, "Title"
Set AVPageView = AVDoc.GetAVPageView
AVPageView.Goto intPage

End Function

ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<<Hey, my VB code was pretty close, maybe I have a future as VB programmer :-)>> I think you just might :)

Perhaps I will delve deeper into the web server issue at a later date.  In the meantime, this will do nicely.

Thanks so much.

Bill