[AccessD] Open PDF

MartyConnelly martyconnelly at shaw.ca
Wed Mar 14 20:40:45 CDT 2007


Re: Open a PDF file from MS Access

Here is another method I used with Acrobat 6.0, may have to be
modified with 7.0

You can then open pdf file with a specific zoom, at a specific page or 
bookmark

Sub RunAdobe()
'for list of opening options see
' http://partners.adobe.com/asn/acrobat/sdk/public/docs/PDFOpenParams.pdf
Dim intRet As Integer
Dim intPage As Integer
Dim strPDF As String
Dim strCommandLine As String
intPage = 3
'note extra quotes needed for shell command
strPDF = """C:\records management\aircanadacasestudy.pdf"""

strCommandLine = """C:\Program Files\Adobe\Acrobat
6.0\Reader\AcroRd32.exe""" & _
" /A " & "page=" & intPage & "&zoom=50,250,100 " & strPDF
Debug.Print strCommandLine
intRet = Shell(strCommandLine, vbMaximizedFocus)
End Sub

To go further you would need full version of Acrobat and purchase SDK
to get Adobe API for $100 and run code like this


Public Function BookM1(a as String)
On Error GoTo ErrorHandler
'Function adds a bookmark for each page in document : a - full path
and filename
Dim JSO As Object
Dim Path As String
Dim r
Dim PGE(2)

Set GApp = CreateObject("Acroexch.app")
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set PDDoc = CreateObject("Acroexch.pddoc")

Path = a
'open avdoc object
If (AVDoc.Open(Path, Path)) Then
' THIS IS THE BIT MISSING FROM THE BOOKS YOU MUST USE AVDOC
'Avdoc opened
Set AVPageView = AVDoc.GetAVPageView
Set PDDoc = AVDoc.GetPDDoc()
Set JSO = PDDoc.GetJSObject

If Not JSO Is Nothing Then
'JSObject opened
PGE(2) = 0 'set ref page to Page 1
PGE(1) = PDDoc.GetNumPages() ' set total number of pages
Do Until PGE(2) = PGE(1)
r = JSO.bookmarkroot.createchild("Page " & PGE(2) + 1, "this.pageNum=" &
PGE(2), PGE(2))
PGE(2) = PGE(2) + 1
Loop
PDDoc.Save PDSaveFull, Path
Else
MsgBox "JSO Failed to Open " & Path
End If
Else
MsgBox "AVDocFailed to Open " & Path
End If

'Exit the function.
exit_BookM1:
r = GApp.CloseAllDocs
Set MyJSObject = Nothing
Set MyPDFDoc = Nothing
Set MyPDFApp = Nothing
r = GApp.Exit

Exit Function

ErrorHandler:
'Filter out the errors.
Select Case Err.number

Case Else
'Display the error number and description.
MsgBox "Error: " & Err.number & ", " & Err.DESCRIPTION & Chr(13) &
Chr(10) &
"Error occurred in BookM1."

End Select

Resume exit_BookM1

End Function

Rocky Smolin at Beach Access Software wrote:

>Thanks David. I switched over to this instead of the FollowHyperlink
>approach.  Worked perfectly once I figured out about getting the API
>function declared.
>
>The FollowHyperlink approach seems cleaner but there must be some drawback
>to it.
>
>Anyway, your code works fine with a second from Andy.  So I'll use it.
>
>Thanks,
>
>Rocky
>
>
>
>
>
> 	
>	
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of David Emerson
>Sent: Wednesday, March 14, 2007 2:02 PM
>To: Access Developers discussion and problem solving
>Subject: Re: [AccessD] Open PDF
>
>Rocky,
>
>I use this function (Not sure where I came across it).  StrFile is the full
>path to the file to open.  It used Windows file association to know what
>program to open the file in:
>
>Function RunApp(strFile As String, bytSize) As Boolean
>     Dim lngRet As Long
>     Dim varTaskID As Variant
>     Dim strRet As String
>
>     ' Enclose FilePath within double quotes so as to take care of embedded
>spaces if any.
>     strFile = Chr(34) & strFile & Chr(34)
>     ' bytSize = 1 for Normal Window, 3 for Maximized Window
>
>     lngRet = ShellExecute(hWndAccessApp, vbNullString, strFile,
>vbNullString, vbNullString, bytSize)
>     If lngRet > 32 Then 'Success
>         strRet = vbNullString
>         lngRet = -1
>         RunApp = True
>     Else
>         RunApp = False
>         Select Case lngRet
>             Case 0 'InadequateMemory
>                 MsgBox "Error:  Out of Memory/Resources!"
>             Case 2 'FileNotFound
>                 MsgBox "Error:  " & strFile & " not found."
>             Case 3 'PathNotFound
>                 MsgBox "Error:  Path not found for file " & strFile & "."
>             Case 11 'BadFormat
>                 MsgBox "Error:  Bad File Format for file " & strFile & "."
>             Case 5
>                 MsgBox "Error:  Unauthorized due to Security restrictions!"
>             Case Else
>                 MsgBox "Error: Unexpected error (Number " & lngRet &
>") for file " & strFile & "."
>         End Select
>     End If
>
>End Function
>
>Regards
>
>David Emerson
>Dalyn Software Ltd
>999 Moonshine Rd, RD 1
>Judgeford, Porirua
>New Zealand 5381
>Phone    0064 4 235-6782
>Fax      0064 4 235-6783
>
>At 15/03/2007, you wrote:
>  
>
>>Dear List:
>>
>>What is the best way to open a PDF file through VBA.  I have the full 
>>path and file name of the PDF file, but I can't count on the version or 
>>location of Acrobat on the target machines.
>>
>>MTIA,
>>
>>Rocky
>>--
>>AccessD mailing list
>>AccessD at databaseadvisors.com
>>http://databaseadvisors.com/mailman/listinfo/accessd
>>Website: http://www.databaseadvisors.com
>>    
>>
>
>--
>AccessD mailing list
>AccessD at databaseadvisors.com
>http://databaseadvisors.com/mailman/listinfo/accessd
>Website: http://www.databaseadvisors.com
>
>--
>No virus found in this incoming message.
>Checked by AVG Free Edition.
>Version: 7.5.446 / Virus Database: 268.18.11/721 - Release Date: 3/13/2007
>4:51 PM
> 
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the AccessD mailing list