Results 1 to 10 of 10
  1. #1
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    How to read a PDF file in MSAccess 2010

    Any help would be appreciated as I am way beyond my skills trying to read these files.
    I am trying to read *.pdf files using VBA. I have tried using some code


    Code:
     Dim AcroApp As Acrobat.CAcroApp
        Dim theForm As Acrobat.CAcroPDDoc
        Dim jso As Object
        Dim text1, text2 As String
      'error occurs here stating"ActiveX component can't create object"
    
    
        Set AcroApp = CreateObject("AcroExch.App")
        Set theForm = CreateObject("AcroExch.PDDoc")
        theForm.Open ("C:\temp\sampleForm.pdf")
        Set jso = theForm.GetJSObject
    
    
        ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    
    
        MsgBox "Values read from PDF: " & text1 & " " & text2
    
    
        ' set a text field
        Dim field2 As Object
        Set field2 = jso.getField("Text2")
    
    
        field2.Value = 13   ' assign the number 13 to the fields value
    
    
        ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    
    
        MsgBox "Values read from PDF: " & text1 & " " & text2
    
    
        theForm.Close
    
    
        AcroApp.Exit
        Set AcroApp = Nothing
        Set theForm = Nothing
    
    
        MsgBox "Done"

    I have set a reference to Adobe 10 Type Library and Adobe Access 3 Type library.
    Any help would be appreciated. I am using Adobe Acrobat Reader X if that helps. I now read them by converting to text file and using FileObject to read the text file and VBA text commands to get the right fields.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Paste this code into a module, it will open ANY file in its Native appliation...

    usage: OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat
    and
    OpenNativeApp "c:\folder\file.doc"
    will open the doc in Word, etc.

    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    But I see you were assigning values so my above solution wont do.

  4. #4
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    How to read and write to PDF file Reply

    Quote Originally Posted by ranman256 View Post
    Paste this code into a module, it will open ANY file in its Native appliation...

    usage: OpenNativeApp "c:\folder\file.pdf"
    will open it in acrobat
    and
    OpenNativeApp "c:\folder\file.doc"
    will open the doc in Word, etc.

    Code:
    'Attribute VB_Name = "modNativeApp"
    'Option Compare Database
    Option Explicit
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Const SW_SHOWNORMAL = 1
    Const SE_ERR_FNF = 2&
    Const SE_ERR_PNF = 3&
    Const SE_ERR_ACCESSDENIED = 5&
    Const SE_ERR_OOM = 8&
    Const SE_ERR_DLLNOTFOUND = 32&
    Const SE_ERR_SHARE = 26&
    Const SE_ERR_ASSOCINCOMPLETE = 27&
    Const SE_ERR_DDETIMEOUT = 28&
    Const SE_ERR_DDEFAIL = 29&
    Const SE_ERR_DDEBUSY = 30&
    Const SE_ERR_NOASSOC = 31&
    Const ERROR_BAD_FORMAT = 11&
    
    Public Sub OpenNativeApp(ByVal psDocName As String)
    Dim r As Long, msg As String
    r = StartDoc(psDocName)
    If r <= 32 Then
        'There was an error
        Select Case r
            Case SE_ERR_FNF
                msg = "File not found"
            Case SE_ERR_PNF
                msg = "Path not found"
            Case SE_ERR_ACCESSDENIED
                msg = "Access denied"
            Case SE_ERR_OOM
                msg = "Out of memory"
            Case SE_ERR_DLLNOTFOUND
                msg = "DLL not found"
            Case SE_ERR_SHARE
                msg = "A sharing violation occurred"
            Case SE_ERR_ASSOCINCOMPLETE
                msg = "Incomplete or invalid file association"
            Case SE_ERR_DDETIMEOUT
                msg = "DDE Time out"
            Case SE_ERR_DDEFAIL
                msg = "DDE transaction failed"
            Case SE_ERR_DDEBUSY
                msg = "DDE busy"
            Case SE_ERR_NOASSOC
                msg = "No association for file extension"
            Case ERROR_BAD_FORMAT
                msg = "Invalid EXE file or error in EXE image"
            Case Else
                msg = "Unknown error"
        End Select
    '    MsgBox msg
    End If
    End Sub
    Private Function StartDoc(psDocName As String) As Long
    Dim Scr_hDC As Long
    Scr_hDC = GetDesktopWindow()
    StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
    End Function
    Thanks for the effort but I need to parse thru the PDF file and extract or add new data (RW). Thanks for the effort

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Is this a form-fill PDF or an OCR PDF?

    Review https://www.accessforums.net/program...lds-46717.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Answer to Junere PDF type

    Quote Originally Posted by June7 View Post
    Is this a form-fill PDF or an OCR PDF?

    Review https://www.accessforums.net/program...lds-46717.html
    June I don't know what a form-fill PDF or an OCR PDF are. I receive a PDF file from an outside entity, it is called "Quarterly Report of CEF", and I currently change the "Quarterly Report of CEF" PDF to a text file using "Save as " text file choice on the Adobe menu. I then parse this new text file using VBA and string commands to find the data I need. I would like to try "reading" the PDF file when parsing. If I can't do that I would like to automate the making of the text file as I am manually completing this task but it would be complicated for new users to correctly and consistently do this process and without the data the Access report would not be created. Once the Access report is created I send the report by email as a PDF file.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    A form-fill document is like the one you provided with the link. It is set up to allow text input into 'fields' on the PDF. Pressing tab key advances to the next 'field'. Need to know the names of these 'fields' for code to reference and pull values.

    OCR - Optical Character Recognition - allows text search within an image file. Depending on how the PDF is created, it can be searchable or it is just a picture.

    Whether or not VBA can automate saving PDF form-fill document to text file might be possible. Probably involve VBA opening and manipulating PDF object. I have done this to split and merge PDF documents. AFAIK, for VBA to open and manipulate PDF object requires an install of Acrobat Professional. I do know my code works at the office where I have AcrobatPro but not at home where I do not have it.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    PDF Adobe Acrobat pro

    Quote Originally Posted by June7 View Post
    A form-fill document is like the one you provided with the link. It is set up to allow text input into 'fields' on the PDF. Pressing tab key advances to the next 'field'. Need to know the names of these 'fields' for code to reference and pull values.

    OCR - Optical Character Recognition - allows text search within an image file. Depending on how the PDF is created, it can be searchable or it is just a picture.

    Whether or not VBA can automate saving PDF form-fill document to text file might be possible. Probably involve VBA opening and manipulating PDF object. I have done this to split and merge PDF documents. AFAIK, for VBA to open and manipulate PDF object requires an install of Acrobat Professional. I do know my code works at the office where I have AcrobatPro but not at home where I do not have it.
    So unless I spend $499.00 for AAPro I am out of luck. Is there anywhere I can get a "cheaper' version say V 7 that will allow me to open a PDF file and parse through the file? IF not how can I automate the creation of a text file from a PDF file? or can I? Thanks for all your help I really appreciate the effort but I seem to always have these esoteric problems that require a Gandalf to solve ;-)

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Here is another recent thread about interacting with PDF. https://www.accessforums.net/modules...ile-46789.html
    I don't know if the poster has AcrobatPro. If you can get the code to work without it, that would indicate some manipulation can be done without AcrobatPro.

    I might do test at home.

    Sorry don't have more info.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Cool PDF Parsing

    Quote Originally Posted by June7 View Post
    Here is another recent thread about interacting with PDF. https://www.accessforums.net/modules...ile-46789.html
    I don't know if the poster has AcrobatPro. If you can get the code to work without it, that would indicate some manipulation can be done without AcrobatPro.

    I might do test at home.

    Sorry don't have more info.
    Thanks for the try but in order to do what I want I need to be able to
    "emulate" Adobe Acrobat as others have done with version 7.0 Adobe Acrobat but I guess Adobe decided enough is enough as my Adobe Reader doesn't have the library to "emulate" Adobe Acrobat.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Learn MSAccess by playing MSAccess Jeopardy
    By pkstormy in forum Sample Databases
    Replies: 4
    Last Post: 11-17-2016, 07:27 AM
  2. MSAccess 2007/2010 Date Picker Replacement - Version 3
    By pkstormy in forum Code Repository
    Replies: 8
    Last Post: 10-06-2015, 05:39 AM
  3. Create Linked Read-Only File
    By kazaccess in forum Access
    Replies: 10
    Last Post: 02-13-2014, 08:43 PM
  4. Replies: 6
    Last Post: 02-24-2012, 06:09 AM
  5. Read text file with LF
    By SteveG in forum Programming
    Replies: 8
    Last Post: 12-24-2011, 09:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums