Results 1 to 4 of 4

Thread: [RESOLVED] Acrobat Automation Error

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Gold Coast, Australia
    Posts
    71

    Resolved [RESOLVED] Acrobat Automation Error

    Hi Again Everyone,

    It seems I only ever ask for help, not give it! Maybe when "I'm a big boy programmer" I'll be able to do a payback!

    Anyway, am having a perplexing problem with trying to merge multiple pdf's into a single pdf using the Acrobat.tlb library.

    I have it referenced (Acrobat 8.0) and I am using XP SP2.

    My problem is the line...Set oMainDoc = CreateObject("AcroExch.PDDoc")
    I tried the command immediately below (now commented out) and the same error occured...Error 430...Class does not support automation etc

    I have tried all sorts of variations on the theme to get it to work to no avail
    Can someone please tell me whats wrong here?
    In every code search I have done, the code used is exactly as I have it and works for them!

    Your help is much appreciated in advance.

    Code:
    Public Function MergePDFFiles(psRawPDFFilesDir As String, _
    psSinglePDFOutputDir As String, _
    psSinglePDFOutputName As String) As Long
    
    'On Error GoTo MyError
    On Error GoTo 0
    Dim lErrNum As Long
    Dim sErrDesc As String
    Dim sMess As String
    Dim bFirstDoc As Boolean
    Dim sRawPDFFilesDir As String
    Dim sSinglePDFOutputDir As String
    Dim sSinglePDFOutputName As String
    'acrobat library
    Dim oMainDoc As Acrobat.AcroPDDoc
    Dim otempdoc As Acrobat.AcroPDDoc
    'Need to use Adobe internal Java Object
    'in order to Add Book marks
    Dim oJSO As Object 'JavaScript Object
    Dim oBookMarkRoot As Object
    Dim oFolder As Scripting.Folder
    Dim saryFileSort() As String
    Dim oFile As Scripting.File
    Dim oFSO As Scripting.FileSystemObject
    Dim sBMName As String
    Dim lPos As Long
    Dim lFile As Long
    Dim lBMPageNo As Long
    
    sRawPDFFilesDir = psRawPDFFilesDir
    sSinglePDFOutputDir = psSinglePDFOutputDir
    sSinglePDFOutputName = psSinglePDFOutputName
    Set oFSO = New Scripting.FileSystemObject
    Set oFolder = oFSO.GetFolder(sRawPDFFilesDir)
    Set oMainDoc = CreateObject("AcroExch.PDDoc")
    'Set oMainDoc = New Acrobat.AcroPDDoc
    
    bFirstDoc = True
    
    If oFolder.Files.Count = 0 Then
        Exit Function 'nothing to do
    End If
    
    'Because the FSO folder files collection does not allow for
    'native sorting, we need to plug all the files into an array to sort
    ReDim saryFileSort(1 To oFolder.Files.Count)
    lFile = 0
    For Each oFile In oFolder.Files
        lFile = lFile + 1
        saryFileSort(lFile) = oFile.Name
    Next
    'do your sort here, or not
    'goUtil.utBubbleSort saryFileSort
    
    For lFile = 1 To UBound(saryFileSort, 1)
        If LCase(Right(saryFileSort(lFile), 4)) = ".pdf" Then
            If bFirstDoc Then 'open the pdf and insert/bookmark first page
                bFirstDoc = False
                Dim IsOpen As Boolean
                IsOpen = oMainDoc.Open(sRawPDFFilesDir & "\" & saryFileSort(lFile))
                Set oJSO = oMainDoc.GetJSObject
                Set oBookMarkRoot = oJSO.bookmarkroot
                sBMName = saryFileSort(lFile)
                lPos = InStr(1, sBMName, "_{", vbBinaryCompare)
                If lPos > 0 Then
                    sBMName = Left(sBMName, lPos - 1) & ".pdf"
                End If
                oBookMarkRoot.CreateChild sBMName, "this.pageNum =0", lFile - 1
            Else 'insert/bookmark rest of pages
                Set otempdoc = CreateObject("AcroExch.PDDoc")
                otempdoc.Open sRawPDFFilesDir & "\" & saryFileSort(lFile)
                'get the Book mark page number before the actual insert of new pages            lBMPageNo = oMainDoc.GetNumPages
                oMainDoc.InsertPages oMainDoc.GetNumPages - 1, otempdoc, 0, otempdoc.GetNumPages, 1
                otempdoc.Close
                sBMName = saryFileSort(lFile)
                lPos = InStr(1, sBMName, "_{", vbBinaryCompare)
                If lPos > 0 Then
                    sBMName = Left(sBMName, lPos - 1) & ".pdf"
                End If
                oBookMarkRoot.CreateChild sBMName, "this.pageNum =" & lBMPageNo, lFile - 1
            End If
        End If
    Next
    oMainDoc.Save 1, sSinglePDFOutputDir & "\" & sSinglePDFOutputName
    oMainDoc.Close
    MergePDFFiles = 33 'saved OK so no error
    
    CLEAN_UP:
            Set oFolder = Nothing
            Set oFile = Nothing
            Set oFSO = Nothing
            Set oBookMarkRoot = Nothing
            Set oJSO = Nothing
            Set oMainDoc = Nothing
            Set otempdoc = Nothing
            Exit Function
    MyError:
            'lErrNum = Err.Number
            'sErrDesc = Err.Description
            'MsgBox sErrDesc
            MergePDFFiles = Err.Number
            'Enter you error handler
            Set oFolder = Nothing
            Set oFile = Nothing
            Set oFSO = Nothing
            Set oBookMarkRoot = Nothing
            Set oJSO = Nothing
            Set oMainDoc = Nothing
            Set otempdoc = Nothing
        End Function

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Acrobat Automation Error

    Hi just a guess

    Shouldn't it be something like

    Dim oApp As Object
    Dim oMainDoc As Object

    Set oApp = CreateObject("Acrobat.Application") ' <== not sure about the syntax
    Set oMainDoc = oApp.Documents.Open(App.Path & "\MyFolder\Myyfile.pdf") ' <== not sure about the syntax
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Gold Coast, Australia
    Posts
    71

    Re: Acrobat Automation Error

    Thanks for that.

    I tried it but the AcroApp library does not have a documents or open method.
    It only has the show and getactivedocument methods which won't work for me because I want to do this in the background.
    Also the app only deals with AvDocs whereas I want to deal with PdDocs so I can merge multiple files into one which I don't think AvDocs can do.

    Any other ideas would be really appreciated though.

    Cheers

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Location
    Gold Coast, Australia
    Posts
    71

    Resolved Re: Acrobat Automation Error

    Have solved it...

    Declaring the variables had to be done in the declarations section not locally within the function.

    As simple as that.

    Thanks Koolskid for your input.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width